Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

old style c macro usage

0 views
Skip to first unread message

Klaus Rudolph

unread,
Dec 28, 2009, 3:14:42 PM12/28/09
to
{ Though the C preprocessor and the C++ preprocessor are not very
different, since you asked about the C preprocessor specifically,
it is considered off topic for comp.lang.c++.moderated.
(The charter states: "articles pertaining solely to the C subset of
the C++ language are off-topic and belong in C newsgroups, such as
comp.lang.c.moderated.")
Please consult a C newsgroup. -mod }


Hi all,

I have to work with a lot of terrible old code which is full of old
style c makros.

There I found something like:

#define M1 yyy
...
#if M1 == xxx
do something
#endif

I am wondering why "do something" is allways in the compiled code. The
"#if M1 == xxx" is always true, only if M1 is assigned to a number like
"#define M1 6".

Can you give me a link to a full description of the c preprocessor syntax?

Thanks


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Stuart Golodetz

unread,
Dec 29, 2009, 3:16:59 AM12/29/09
to
On 28/12/2009 20:14, Klaus Rudolph wrote:
> { Though the C preprocessor and the C++ preprocessor are not very
> different, since you asked about the C preprocessor specifically,
> it is considered off topic for comp.lang.c++.moderated.
> (The charter states: "articles pertaining solely to the C subset of
> the C++ language are off-topic and belong in C newsgroups, such as
> comp.lang.c.moderated.")
> Please consult a C newsgroup. -mod }
>
>
> Hi all,
>
> I have to work with a lot of terrible old code which is full of old
> style c makros.
>
> There I found something like:
>
> #define M1 yyy
> ...
> #if M1 == xxx
> do something
> #endif
>
> I am wondering why "do something" is allways in the compiled code. The
> "#if M1 == xxx" is always true, only if M1 is assigned to a number like
> "#define M1 6".

It's not always in the compiled code - I just tried it. Specifically,
this fails to compile:

#define M1 5

#if M1 == 6
void f() {}
#endif

int main()
{
f();
return 0;
}

> Can you give me a link to a full description of the c preprocessor syntax?

http://lmgtfy.com/?q=c+preprocessor+syntax

(I'd observe in passing that there's an == example under 4.2.5 in the
first link which came up for me.)

Regards,
Stu

0 new messages