By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,605 Members | 1,370 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,605 IT Pros & Developers. It's quick & easy.

Regarding structure having members under conditional compilation

P: n/a
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!!! ;-)

Nov 15 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
sa*****@yahoo.co.in wrote:
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.
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.

Nov 15 '06 #2

P: n/a

sa*****@yahoo.co.in wrote:
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.

Nov 15 '06 #3

P: n/a


sa*****@yahoo.co.in wrote On 11/15/06 11:34,:
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.
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.

--
Er*********@sun.com

Nov 15 '06 #4

P: n/a
In article <1163610691.393828@news1nwk>,
Eric Sosman <Er*********@sun.comwrote:
>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.
Nov 15 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.