* stupid C preprocessor question
@ 2004-03-24 15:39 Steven G. Kargl
2004-03-24 16:28 ` Zack Weinberg
0 siblings, 1 reply; 6+ messages in thread
From: Steven G. Kargl @ 2004-03-24 15:39 UTC (permalink / raw)
To: gcc
I learned K&R C several years ago and now have a need
to return to programming in C. Is the following legal C?
#include <math.h>
double tmp(void) {
double x;
x = sin(1.);
#if 0
Can't do this
#endif
return x;
}
--
Steve
http://troutmask.apl.washington.edu/~kargl/
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: stupid C preprocessor question
2004-03-24 15:39 stupid C preprocessor question Steven G. Kargl
@ 2004-03-24 16:28 ` Zack Weinberg
2004-03-24 16:35 ` Steven G. Kargl
0 siblings, 1 reply; 6+ messages in thread
From: Zack Weinberg @ 2004-03-24 16:28 UTC (permalink / raw)
To: Steven G. Kargl; +Cc: gcc
"Steven G. Kargl" <kargl@troutmask.apl.washington.edu> writes:
> I learned K&R C several years ago and now have a need
> to return to programming in C. Is the following legal C?
The only bit of your code that is objectionable is this bit
> #if 0
> Can't do this
> #endif
which provokes undefined behavior, because of the unmatched single
quote. Use a real comment (/* Can't do this */) instead.
zw
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: stupid C preprocessor question
2004-03-24 16:28 ` Zack Weinberg
@ 2004-03-24 16:35 ` Steven G. Kargl
2004-03-24 17:47 ` Zack Weinberg
2004-03-24 18:02 ` Robert Dewar
0 siblings, 2 replies; 6+ messages in thread
From: Steven G. Kargl @ 2004-03-24 16:35 UTC (permalink / raw)
To: Zack Weinberg; +Cc: gcc
Zack Weinberg wrote:
> "Steven G. Kargl" <kargl@troutmask.apl.washington.edu> writes:
>
> > I learned K&R C several years ago and now have a need
> > to return to programming in C. Is the following legal C?
>
> The only bit of your code that is objectionable is this bit
>
> > #if 0
> > Can't do this
> > #endif
>
> which provokes undefined behavior, because of the unmatched single
> quote. Use a real comment (/* Can't do this */) instead.
>
I'm translating a large chunk of Fortran to C. The use of
#if 0 ... #endif makes it much easier. I don't have access to
the C99 standard, but Harbison and Steele state in a discussion
of #if ... #endif constructs that "A group of lines that is
discarded is not processed by the preprocessor." (H&S, 5th ed.
page 62).
kargl[202] gcc -c a.c
a.c:5:7: missing terminating ' character
It appears that gcc is preprocessing the discarded lines.
--
Steve
http://troutmask.apl.washington.edu/~kargl/
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: stupid C preprocessor question
2004-03-24 16:35 ` Steven G. Kargl
@ 2004-03-24 17:47 ` Zack Weinberg
2004-03-24 18:02 ` Robert Dewar
1 sibling, 0 replies; 6+ messages in thread
From: Zack Weinberg @ 2004-03-24 17:47 UTC (permalink / raw)
To: Steven G. Kargl; +Cc: gcc
"Steven G. Kargl" <kargl@troutmask.apl.washington.edu> writes:
>
> I'm translating a large chunk of Fortran to C. The use of
> #if 0 ... #endif makes it much easier.
I don't see why /* */ don't work for you.
> I don't have access to the C99 standard, but Harbison and Steele
> state in a discussion of #if ... #endif constructs that "A group of
> lines that is discarded is not processed by the preprocessor." (H&S,
> 5th ed. page 62).
>
> kargl[202] gcc -c a.c
> a.c:5:7: missing terminating ' character
>
> It appears that gcc is preprocessing the discarded lines.
What H&S mean is that if you write
#if 0
#define FOO bar
#endif
FOO is not defined as a macro. Lines inside a failed #if are still
tokenized (they have to be - how else to find the #endif?
zw
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: stupid C preprocessor question
2004-03-24 16:35 ` Steven G. Kargl
2004-03-24 17:47 ` Zack Weinberg
@ 2004-03-24 18:02 ` Robert Dewar
2004-03-24 18:40 ` Steven G. Kargl
1 sibling, 1 reply; 6+ messages in thread
From: Robert Dewar @ 2004-03-24 18:02 UTC (permalink / raw)
To: Steven G. Kargl; +Cc: Zack Weinberg, gcc
Steven G. Kargl wrote:
> I don't have access to
> the C99 standard, but Harbison and Steele state in a discussion
> of #if ... #endif constructs that "A group of lines that is
> discarded is not processed by the preprocessor." (H&S, 5th ed.
> page 62).
This is just plain wrong, or rather casually careless.
> It appears that gcc is preprocessing the discarded lines.
The lines discarded still have to be valid sequences of tokens.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: stupid C preprocessor question
2004-03-24 18:02 ` Robert Dewar
@ 2004-03-24 18:40 ` Steven G. Kargl
0 siblings, 0 replies; 6+ messages in thread
From: Steven G. Kargl @ 2004-03-24 18:40 UTC (permalink / raw)
To: Robert Dewar; +Cc: Zack Weinberg, gcc
Robert Dewar wrote:
> Steven G. Kargl wrote:
>
> > I don't have access to
> > the C99 standard, but Harbison and Steele state in a discussion
> > of #if ... #endif constructs that "A group of lines that is
> > discarded is not processed by the preprocessor." (H&S, 5th ed.
> > page 62).
>
> This is just plain wrong, or rather casually careless.
>
H&S have a correct explanation. It's my reading comprehesion
after a 14+ hour day seems to be diminished.
--
Steve
http://troutmask.apl.washington.edu/~kargl/
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2004-03-24 15:44 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-03-24 15:39 stupid C preprocessor question Steven G. Kargl
2004-03-24 16:28 ` Zack Weinberg
2004-03-24 16:35 ` Steven G. Kargl
2004-03-24 17:47 ` Zack Weinberg
2004-03-24 18:02 ` Robert Dewar
2004-03-24 18:40 ` Steven G. Kargl
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).