Why no switch on pointers?

A switch compares the variable with a set of compile-time constants. Other than null, I can’t see any valid compile time constants that you might compare a pointer with. For example:

switch (ptr) { 
   case &var1: printf ("Pointing to var1"); break;
   case &var2: printf ("Pointing to var2"); break;
}

var1 and var2 are likely different in each run of the program, and would not be compile time constants. One possibility might be that they are addresses of memory-mapped ports that are always fixed, but otherwise I don’t see how you could easily expand this from your two cases (null / not-null).

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)