Article View: comp.std.c
Article #4353Re: defined(FOO) in macros
From: William E. Aitken
Date: Mon, 13 Nov 1995 05:35
Date: Mon, 13 Nov 1995 05:35
64 lines
2539 bytes
2539 bytes
In article <48190c$bak@nyx10.cs.du.edu>, Colin Plumb <colin@nyx10.cs.du.edu> 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 >----^ >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? >Replacing the definition of HAVE_FOO with the equivalent (for my >purposes - I understand that there is a distinction) construction: > >#if defined(FOO) >#define HAVE_FOO 1 >#else >#define HAVE_FOO 0 >#endif > >works fine. > >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. >-- > -Colin You should count yourself lucky that your hard disk wasn't re-formatted. To quote the standard [Clause 6.8.1, bottom of page 86] ''If the token \verb+defined+ is generated as a result of this replacement process or use of the \verb+defined+ operator does not match one of the two specified forms prior to macro replacement, the behavior is undefined.'' The replacement process being referred to is the one that excpands macros in the controlling expressions of #if's and #elif's. -- William E. Aitken | Formal verification is the email: aitken@halcyon.com | future of computer science --- Snail: 8500 148th Ave NE #H1026 Redmond WA | Always has been, always will be. ===============================================================================
Technical Details
Message-ID:
<486len$j6j@news1.halcyon.com>Path:
arc1-ca.pugleaf.net!news1.halcyon.com!coho!aitkenReferences:
<48190c$bak@nyx10.cs.du.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!news1.halcyon.com!coho!aitken From: aitken@coho.halcyon.com (William E. Aitken) Newsgroups: comp.std.c Subject: Re: defined(FOO) in macros Date: 13 Nov 1995 05:35:19 GMT Organization: Northwest Nexus, Inc. - Professional Internet Services Message-ID: <486len$j6j@news1.halcyon.com> References: <48190c$bak@nyx10.cs.du.edu> NNTP-Posting-Host: coho.halcyon.com