If I write something like
#define INT_PTR int*
INT_PTR ptr4, ptr5, ptr6;
In this case only ptr4 is pointer to an integer, rest of the values (ptr5 and ptr6) are integers. How they are taking the integer value ? Either it should give some compilation error.
Why is it this way that compiler is treating ptr5 and ptr6 as integers.
This actually has nothing to do with the
#define, which is simply a textual replacement.After the preprocessor phase (when the substitution takes place), you end up with:
and, because the
*binds to the variable rather than the type, you create one integer pointer and two integers.This is why I prefer to write:
rather than:
since the former makes it clearer that the
*belongs to the variable. If you want to define a new type in C, the command is, surprisingly enough,typedef🙂That defines a new type that will apply to all variables that follow it, rather than just substituting text, as per the macro. In other words, the type
INTPTR(int *) applies to all three ofptr4,ptr5andptr6.