QNX 6.3.0: Problems with -D and #if

bridged with qnx.development_tools
Post Reply
Bjorn Rudolfsson

QNX 6.3.0: Problems with -D and #if

Post by Bjorn Rudolfsson » Wed Jun 07, 2006 1:59 pm

Hi all,

I've run into a bit of a strange problem with QNX 6.3.0 and gcc 3.4.4.
If I define a macro using -D, say -DFOO=BAR, and then try to check that
in the code using #if (FOO == BAR) ... #endif, it won't work. By the
looks of it it completely ignores this construct; even when I skip -D in
the command line, the code with the #if statement will be included! This
is really weird. I also have Cygwin installed on the same computer and
tried with it's gcc (which is also 3.4.4) and have the same result.

Has anyone had any similar problems? Just defining the macro without
specified value (i.e. -DFOO and checking with #ifdef FOO) works just fine...

I'm running all this on a WinXP SP2 machine, building for a SH4 system.

Would be very grateful for any help.

Cheers,
Bjorn Rudolfsson

Wojtek Lerch

Re: QNX 6.3.0: Problems with -D and #if

Post by Wojtek Lerch » Wed Jun 07, 2006 2:58 pm

"Bjorn Rudolfsson" <rudolfsson@svox.com> wrote in message
news:e66m3u$mfn$1@inn.qnx.com...
If I define a macro using -D, say -DFOO=BAR, and then try to check that in
the code using #if (FOO == BAR) ... #endif, it won't work. By the looks
of it it completely ignores this construct; even when I skip -D in the
command line, the code with the #if statement will be included! This is
really weird. I also have Cygwin installed on the same computer and tried
with it's gcc (which is also 3.4.4) and have the same result.
In an #if expression, any identifier that remains after macro expansion is
considered to be zero. When you define FOO to be BAR but BAR is not a
macro, your

#if FOO == BAR

turns into

#if BAR == BAR

which doesn't change anything -- either way, you're comparing zero to zero.

Adam Mallory

Re: QNX 6.3.0: Problems with -D and #if

Post by Adam Mallory » Wed Jun 07, 2006 3:11 pm

Bjorn Rudolfsson wrote:
Hi all,

I've run into a bit of a strange problem with QNX 6.3.0 and gcc 3.4.4.
If I define a macro using -D, say -DFOO=BAR, and then try to check that
in the code using #if (FOO == BAR) ... #endif, it won't work. By the
looks of it it completely ignores this construct; even when I skip -D in
the command line, the code with the #if statement will be included! This
is really weird. I also have Cygwin installed on the same computer and
tried with it's gcc (which is also 3.4.4) and have the same result.

Has anyone had any similar problems? Just defining the macro without
specified value (i.e. -DFOO and checking with #ifdef FOO) works just
fine...

I'm running all this on a WinXP SP2 machine, building for a SH4 system.

Would be very grateful for any help.

Cheers,
Bjorn Rudolfsson
Are you actually doing a non-arithmetic #if ? (ie. are you really doing
#if (FOO==BAR) ?? ). I can do the following:

....
#if (FOO==10)
#error WE HIT THIS
#endif
.....

Then do a -DFOO=10 and I see my #if condition hit; conversely, if I
change the #if (FOO==10) to #if (FOO==11) and then rebuild, I don't see
the #error. My environment is WindowsXPSP2, 630SP2 building for all
architectures (though it shouldn't matter in this case).


-Adam

Bjorn Rudolfsson

Re: QNX 6.3.0: Problems with -D and #if

Post by Bjorn Rudolfsson » Thu Jun 08, 2006 1:07 pm

Wojtek Lerch wrote:
"Bjorn Rudolfsson" <rudolfsson@svox.com> wrote in message
news:e66m3u$mfn$1@inn.qnx.com...
If I define a macro using -D, say -DFOO=BAR, and then try to check that in
the code using #if (FOO == BAR) ... #endif, it won't work. By the looks
of it it completely ignores this construct; even when I skip -D in the
command line, the code with the #if statement will be included! This is
really weird. I also have Cygwin installed on the same computer and tried
with it's gcc (which is also 3.4.4) and have the same result.

In an #if expression, any identifier that remains after macro expansion is
considered to be zero. When you define FOO to be BAR but BAR is not a
macro, your

#if FOO == BAR

turns into

#if BAR == BAR

which doesn't change anything -- either way, you're comparing zero to zero.

BAR is a macro in this case. Actually looks like its not a gcc problem
but a Momentiqs problem. Works from the command line, but not from the
IDE. If I replace BAR with a number it works, and then I can build with
-DFOO=BAR until I do a clean. So I guess the IDE generates the macros in
some makefile somewhere which gets whacked when you do a clean.

Thanks for the tips anyway, I'll see if I can figure out where it
stashes the macro definitions...

Cheers,
Bjorn

Post Reply

Return to “qnx.development_tools”