Defining syntax at the top

Inside my functions I have this phrase that I use quite frequently:

((AAAA *)(BBBB->next + sizeof(CCCC)))

Where AAAA,BBBB, and CCCC are different structs and I’m casting the pointer to the struct AAAA (by the (AAAA *)). My question is, since I do this so much, can I just define this at the top of the file?

#define BBBBNext ((AAAA *)(BBBB->next + sizeof(CCCC)))

Once I use it can will C modify the BBBB value based on where in the code I’m? As at different points of the code BBBB will change, and I want a shorter way of writing that huge chunk of code to make the code easier to read.

So instead of having to write:

((AAAA *)(BBBB->next + sizeof(CCCC))) = 1;

I can just write

BBBBNext = 1;

BBBB is not defined at runtime, and only created when needed

Source: syntax

Leave a Reply