Reputation: 19
I have a question in C. I have a structure whose definition is like this.
struct c1
{
int a ;
int b ;
#ifdef _UNION_DEFINED
union {
#endif
float c;
float d;
#ifdef _UNION_DEFINED
};
#endif
};
The above structure will enable the union if the flag _UNION_DEFINED is enabled. But I want to achieve the same thing dynamically during the run time. Like if a function returns true, then the union should be enabled, else the union should not be defined. Can anyone please tell me if this could be acheived.
Thanks, d
Upvotes: 0
Views: 289
Reputation: 399823
No, that can't be achieved. C is a typically a static, compiled language. This means that when the program runs, there is no meta information (like type information) left, all there is is the raw machine code.
You can perhaps define both structures, then at run-time choose the proper one as needed.
Upvotes: 2