Connecting Tech Pros Worldwide Forums | Help | Site Map

Regarding structure having members under conditional compilation

sam_cit@yahoo.co.in
Guest
 
Posts: n/a
#1: Nov 15 '06
Hi Everyone,

I have a structure typedefed as

typedef strcut
{
#if(MACRO == TRUE)
int a;
int b;
#endif
} SAMPLE_STRUCT;

Now does this give compile properly? If not, i might be expected to
add another temp variable in the structure which might not be used by
my application at all, is there any workaround for this scenario?

Thanks in advance!!! ;-)


santosh
Guest
 
Posts: n/a
#2: Nov 15 '06

re: Regarding structure having members under conditional compilation


sam_cit@yahoo.co.in wrote:
Quote:
Hi Everyone,
>
I have a structure typedefed as
>
typedef strcut
{
#if(MACRO == TRUE)
int a;
int b;
#endif
} SAMPLE_STRUCT;
>
Now does this give compile properly?
Yes, if MACRO is TRUE.
Quote:
If not, i might be expected to
add another temp variable in the structure which might not be used by
my application at all, is there any workaround for this scenario?
Yes, encapsulate the entire typedef with conditional compilation
directives.

insik.park@gmail.com
Guest
 
Posts: n/a
#3: Nov 15 '06

re: Regarding structure having members under conditional compilation



sam_cit@yahoo.co.in wrote:
Quote:
Hi Everyone,
>
I have a structure typedefed as
>
typedef strcut
{
#if(MACRO == TRUE)
int a;
int b;
#endif
} SAMPLE_STRUCT;
>
Now does this give compile properly? If not, i might be expected to
add another temp variable in the structure which might not be used by
my application at all, is there any workaround for this scenario?
>
Thanks in advance!!! ;-)
This is the sort of thing you can easily find out for yourself. Just
make a "test.c" file and run it through the compiler. But to answer
your question, yes, it compiles fine.

Eric Sosman
Guest
 
Posts: n/a
#4: Nov 15 '06

re: Regarding structure having members under conditional compilation




sam_cit@yahoo.co.in wrote On 11/15/06 11:34,:
Quote:
Hi Everyone,
>
I have a structure typedefed as
>
typedef strcut
{
#if(MACRO == TRUE)
int a;
int b;
#endif
} SAMPLE_STRUCT;
>
Now does this give compile properly?
If the compiler issues a diagnostic, it has behaved
"properly." If it doesn't, it has behaved "improperly."

If you change `strcut' to `struct', then what happens
depends on how MACRO is defined. If the #if test fails and
the `a' and `b' declarations are omitted, then the compiler
acts "properly" if and only if it emits a diagnostic.
Quote:
If not, i might be expected to
add another temp variable in the structure which might not be used by
my application at all, is there any workaround for this scenario?
What do you mean by "is there any workaround?" What are
you trying to achieve? A struct containing no elements -- if
C permitted such a thing, which it doesn't -- seems a rather
useless object, not likely to help you toward any goal I can
think of off-hand.

--
Eric.Sosman@sun.com

Richard Tobin
Guest
 
Posts: n/a
#5: Nov 15 '06

re: Regarding structure having members under conditional compilation


In article <1163610691.393828@news1nwk>,
Eric Sosman <Eric.Sosman@sun.comwrote:
Quote:
>A struct containing no elements -- if
>C permitted such a thing, which it doesn't -- seems a rather
>useless object, not likely to help you toward any goal I can
>think of off-hand.
There's not much use for a struct with no members, but there are
plenty of uses for a struct that *might* have no members. For
example, a library might provide a structure having various members
depending on compile-time options, and some combination of options
might result in none being needed. Having to change function
definitions just because some particular application doesn't need any
of the optional features is just an annoyance.

-- Richard
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
Closed Thread