[fpc-pascal] Porting C macro

Henry Vermaak henry.vermaak at gmail.com
Tue Mar 12 00:03:03 CET 2013


On Mon, Mar 11, 2013 at 11:26:57PM +0100, Darius Blaszyk wrote:
>  
> 
> I'm stuck porting a macro from C. Below is the original define. The
> part I'm struggeling with is the right most part after the - sign.
> 
> 
> #define GETNEXT(x) ((LList *)(((char *) x) - ((char *) & (((LList
> *)0)^.next))))

I'm assuming that the "^." should be "->", in which case the last bit is
doing the same as the offsetof() macro.  So the macro is subtracting the
offset in bytes of the "next" member of the LList struct from x, then
casting it to (LList *).

I'd wager that the GETNEXT() isn't actually doing what it says, but
something more like container_of() (because it's _subtracting_ the
offset).  I may be wrong, though, do you have an example of its usage?

Henry



More information about the fpc-pascal mailing list