Tak-Shing Chan <t.****@gold.ac.ukwrites:
On Wed, 26 Jul 2006, Bit Byte wrote:
>I've come accross the following macro:
#define ARR_DIMS(a) \ 66 ((int *) (((char *) (a)) + sizeof(ArrayType)))
I know what it means (from reading the rest of the code)., but I
wonder could someone please explain how to interpret it ?
I believe that this macro will not even compile.
Well, assuming it does work, my guess is that what you actually have is:
65 #define ARR_DIMS(a) \
66 ((int *) (((char *) (a)) + sizeof(ArrayType)))
The compiler deletes <'\' newline>, thus pasting the two
lines together.
'66' makes no sense, so maybe that's a line number displayed
by some tool and not part of the program.
((char *) (a)) + sizeof(ArrayType) points 'sizeof(ArrayType)'
bytes beyond the pointer 'a', which presumably points to
an object of type ArrayType. (A struct describing an array?)
(int*) casts that pointer to int*, thus you get a pointer to
a chunk of 'int's memory immediately beyond the ArrayType object.
Finally, the () surrounding the whole thing and the () around the 'a' is
to make sure it can be used as a normal expression, otherwise e.g.
ARR_DIMS(a + 3)
would be wrong - the '+ 3' would apply to (char *)a instead of to a.
--
Hallvard