Article View: comp.std.c
Article #4351Re: defined(FOO) in macros
From: Thad Smith
Date: Sun, 12 Nov 1995 05:19
Date: Sun, 12 Nov 1995 05:19
51 lines
2112 bytes
2112 bytes
In article <48190c$bak@nyx10.cs.du.edu>, colin@nyx10.cs.du.edu (Colin Plumb) wrote: >I noticed that a DEC's Alpha compiler breaks on > >host% cat > foo.f <<EOF >#ifndef HAVE_FOO >#define HAVE_FOO defined(FOO) >#endif > >#if HAVE_FOO >#error No, we have FOO >#else >#error Yes, we have no FOO >#endif >EOF >host% cc -migrate foo.c >cc: Warning: foo.c, line 5: Spurious token(s) ignored on preprocessor directive line. >#if HAVE_FOO >----^ I assume that the compiler would continue to translate the file with the warning. Spurious warnings are allowed in Standard C, although the text of this one appears incorrect. >cc: Error: foo.c, line 8: #error Yes, we have no FOO >#error Yes, we have no FOO >-^ >cc: Warning: foo.c, line 9: Source file does not contain any declarations. >#endif >------^ > >Now, the second two diagnostics are fine, but is the compiler allowed to >not recognize "defined(FOO)" when it appears as part of a macro expansion? No it isn't. Macro replacements are explicitly performed in the constant expression following "#if ": "Prior to evaluation, macro invocations in the list of preprocessing tokens that will become the controlling constant expression are replaced (except for this macro names modified by the _defined_ unuary operator), just as in normal text". >Now, I don't think this is allowed to fail, but my understanding of >phases of translation is imperfect (e.g. my recent gaffe about breaking >backslash-escapes across lines) and I'm having a hard time producing a >derivation of this fact from the standard so I can write a sufficiently >smug bug report. Nothing has failed as far as the Standard is concerned (since only a warning was given), but the warning text is bogus. Thad
Technical Details
Message-ID:
<1GYpwQ9ytNtZ084yn@csn.net>Path:
arc1-ca.pugleaf.net!teal.csn.net!not-for-mailReferences:
<48190c$bak@nyx10.cs.du.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!teal.csn.net!not-for-mail From: thads@csn.net (Thad Smith) Newsgroups: comp.std.c Subject: Re: defined(FOO) in macros Date: 11 Nov 1995 22:19:17 -0700 Organization: T3 Systems Message-ID: <1GYpwQ9ytNtZ084yn@csn.net> References: <48190c$bak@nyx10.cs.du.edu> Reply-To: ThadSmith@acm.org NNTP-Posting-Host: 199.117.27.22