This is the mail archive of the
mailing list for the GCC project.
Re: #elseif and #ifdef funnies
- To: Alex Buell <alex dot buell at tahallah dot demon dot co dot uk>
- Subject: Re: #elseif and #ifdef funnies
- From: Zack Weinberg <zack at codesourcery dot com>
- Date: Wed, 31 Oct 2001 17:48:48 -0800
- Cc: Mailing List - GCC <gcc at gcc dot gnu dot org>
- References: <Pine.LNX.firstname.lastname@example.org>
On Thu, Nov 01, 2001 at 12:59:42AM +0000, Alex Buell wrote:
> I just stumbled across something strange with the #elseif and #elif
> pragmas tonight. Here's a program snippet:
> #include <stdio.h>
> /* #define one */
> #define two 1
> int main(int argc, char *argv)
> #if defined(one)
> printf("One found\n");
> #elif defined(two)
> printf("Two found\n");
> printf("One and two not found\n");
> return 0;
> This works, produces the expected output 'Two found'. However, if I do a
> s/elif/elseif, and compile it, the output is wrong, it prints 'One and two
There is no "#elseif" preprocessing directive.
You don't get a complaint from the preprocessor because the invalid
directive is inside a failed conditional group. Perhaps it will be
clearer if I illustrate it thus:
... stuff ...
... more stuff ...
For all GCC knows, "#nonsense directive" is a Frobozz Magic CC
extension, properly disabled by #if, and therefore GCC should not
complain about it.
Uncomment the #define one in your example and you'll get a hard error
from GCC (both 2.95.x and 3.0.x tested).
A case could be made for specifically recognizing #elsif and #elseif
and complaining about them even in failed conditional blocks. However,
I suspect it would only help a few people.