D
Dmitri Vorobiev
Hello group,
Is it possible to check the presence of a structure member at compile
time using only the C preprocessor?
What I have in mind could look like the following.
Suppose the structures s1 and s2 look like
struct s1 {
int A;
......
int Z;
}
struct s2 {
int B;
......
int Z;
}
Then this code snippet
#if EXISTS(s1, A)
#error struct s has a member A
#else
#error struct s has no member A
#endif
needs to produce the "struct s has a member A" message, while this one
#if EXISTS(s2, A)
#error struct s has a member A
#else
#error struct s has no member A
#endif
needs to produce the "struct s has no member A".
How do I go about defining the macro EXISTS in such case? Is it at all
possible?
Thanks,
Dmitri
Is it possible to check the presence of a structure member at compile
time using only the C preprocessor?
What I have in mind could look like the following.
Suppose the structures s1 and s2 look like
struct s1 {
int A;
......
int Z;
}
struct s2 {
int B;
......
int Z;
}
Then this code snippet
#if EXISTS(s1, A)
#error struct s has a member A
#else
#error struct s has no member A
#endif
needs to produce the "struct s has a member A" message, while this one
#if EXISTS(s2, A)
#error struct s has a member A
#else
#error struct s has no member A
#endif
needs to produce the "struct s has no member A".
How do I go about defining the macro EXISTS in such case? Is it at all
possible?
Thanks,
Dmitri