Here is the structure used in the program:
struct basic_block { void * aux; };
Now:
- At run time, there are several instances of
basic_block
. - The program works in stages / passes, which are performed one by one.
- The
aux
field is intended to store the stages and basic_block
specific data during the execution of the stage and is freed by the scene itself (so the next stage can reuse it). That is why it is void *
.
My scene uses aux
to store the struct
, so every time I want to access something, I need to throw:
( (struct a_long_struct_name *) (bb->aux))->foo_field = foo;
Now, my problem: every time this is done, it is pain, and it is difficult to read when it is part of more complex expressions. My suggested solution: use the macro to execute for me:
#define MY_DATA(bb) \ ( (struct a_long_struct_name *) (bb)->aux)
Then I can access my data with:
MY_DATA(bb)->foo_field = foo;
But: I cannot use MY_DATA(bb)
myself as an L-value (for malloc
), so I use this macro, this is not a good idea:
MY_DATA(bb) = malloc (sizeof (struct a_long_struct_name));
My question is:
What can I do to access aux
clean way and still be able to use it as an L-value.
source share