public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: #elsif
@ 1998-04-08  2:13 SXTHREE
  0 siblings, 0 replies; 13+ messages in thread
From: SXTHREE @ 1998-04-08  2:13 UTC (permalink / raw)
  To: phdm; +Cc: egcs

I do not think elsif is a standard preprocessor directive.
C++ standards say the correct directive is "elif".
(Or maybe I missed some versions of the standard).
Seems strange gcc accepts this construct without warnings.

FM

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: #elsif
  1998-04-08 23:35     ` #elsif Paul Eggert
  1998-04-08 21:20       ` #elsif Philippe De Muyter
  1998-04-08 21:45       ` #elsif Gavin Romig-Koch
@ 1998-04-09 17:44       ` Joern Rennecke
  2 siblings, 0 replies; 13+ messages in thread
From: Joern Rennecke @ 1998-04-09 17:44 UTC (permalink / raw)
  To: Paul Eggert; +Cc: gavin, phdm, gcc2, egcs

> I assume that you do not want to make a special case for `elsif' only.
> (That would be odd; it wouldn't catch other misspellings like `elseif'.)

Yes, if we warn for elsif, we should have a like warning for elseif.
Both are misspellings of elif that mirror a programming language and
might thus be mistaken for the real thing.  They are special because they
are supposedly meant to end the commenting out.  If there were likely
misspellings of #endif that could be mistaken for the real thing doe to
the similarity with another language (hmmm... maybe #fi would qualify?),
that these should also be warned about.

The warning for such a specific test should not just be something
vanilla like unrecognized #-directive, since that could make people
think we warned about all unrecognized directives.
It should somehow point out the assumed error.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: #elsif
  1998-04-08 21:13         ` #elsif Paul Eggert
@ 1998-04-09  8:27           ` Joe Buck
  0 siblings, 0 replies; 13+ messages in thread
From: Joe Buck @ 1998-04-09  8:27 UTC (permalink / raw)
  To: Paul Eggert; +Cc: phdm, gcc2, egcs

> I just thought of one other useful wrinkle: suppress the warning if
> the unknown directive is in a system include file.

Only if that feature doesn't tempt us to put sloppy code into libstdc++
headers.



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: #elsif
  1998-04-08 21:20       ` #elsif Philippe De Muyter
  1998-04-08 21:13         ` #elsif Paul Eggert
@ 1998-04-09  3:09         ` Nick Ing-Simmons
  1 sibling, 0 replies; 13+ messages in thread
From: Nick Ing-Simmons @ 1998-04-09  3:09 UTC (permalink / raw)
  To: phdm; +Cc: egcs, gavin, Paul Eggert, gcc2

Philippe De Muyter <phdm@macqel.be> writes:
>> I assume that you do not want to make a special case for `elsif' only.
>> (That would be odd; it wouldn't catch other misspellings like `elseif'.)
>> But if we report _all_ misspelled directives, then we run afoul of the
>> examples that caused RMS to change cccp.c to behave the way it does
>> today.
>> 
>> I wouldn't mind adding the checking to -W (or perhaps to -Wundef); but
>> I don't think it should be on by default.
>> 
>Could you rather warn for every unrecognized directive, even without -W or
>-Wall, but have a list of directives accepted by other compilers for which
>you would not complain ?

What if #elsif is supported by another compiler? 

-- 
Nick Ing-Simmons <nik@tiuk.ti.com>
Via, but not speaking for: Texas Instruments Ltd.



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: #elsif
  1998-04-08 15:08   ` #elsif Gavin Romig-Koch
@ 1998-04-08 23:35     ` Paul Eggert
  1998-04-08 21:20       ` #elsif Philippe De Muyter
                         ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: Paul Eggert @ 1998-04-08 23:35 UTC (permalink / raw)
  To: gavin; +Cc: phdm, gcc2, egcs

   Date: Wed, 8 Apr 1998 10:16:11 -0400 (EDT)
   From: Gavin Romig-Koch <gavin@cygnus.com>

   The syntax of preprocessing directives are clearly spelled out,

Yes; here's the definition in the standard.

	A preprocessing directive consists of a sequence of
	preprocessing tokens that begins with a `#' preprocessing
	token that is either the first character in the source file
	(optionally after white space containing no new-line
	characters) or that follows white space containing at least
	one new-line character, and is ended by the next new-line
	character.

Draft C9x changes this wording slightly, but the change doesn't matter
for our purposes.

   and "#elsif" does not fit.

I don't see why not.  `#elsif' is a sequence of preprocessing tokens,
all alone in a line; this fits the definition quoted above.


   From: Joern Rennecke <amylaar@cygnus.co.uk<>
   Date: Wed, 8 Apr 1998 15:08:47 +0100 (BST)

   wthe standard allows any number of warnings, no matter how bogus
   they are.  So why not always warn about #elsif

I assume that you do not want to make a special case for `elsif' only.
(That would be odd; it wouldn't catch other misspellings like `elseif'.)
But if we report _all_ misspelled directives, then we run afoul of the
examples that caused RMS to change cccp.c to behave the way it does
today.

I wouldn't mind adding the checking to -W (or perhaps to -Wundef); but
I don't think it should be on by default.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: #elsif
  1998-04-08 23:35     ` #elsif Paul Eggert
  1998-04-08 21:20       ` #elsif Philippe De Muyter
@ 1998-04-08 21:45       ` Gavin Romig-Koch
  1998-04-09 17:44       ` #elsif Joern Rennecke
  2 siblings, 0 replies; 13+ messages in thread
From: Gavin Romig-Koch @ 1998-04-08 21:45 UTC (permalink / raw)
  To: Paul Eggert; +Cc: phdm, gcc2, egcs

Paul Eggert writes:
 >    Date: Wed, 8 Apr 1998 10:16:11 -0400 (EDT)
 >    From: Gavin Romig-Koch <gavin@cygnus.com>
 > 
 >    The syntax of preprocessing directives are clearly spelled out,
 > 
 > Yes; here's the definition in the standard.
 > 
 > 	A preprocessing directive consists of a sequence of
 > 	preprocessing tokens that begins with a `#' preprocessing
 > 	token that is either the first character in the source file
 > 	(optionally after white space containing no new-line
 > 	characters) or that follows white space containing at least
 > 	one new-line character, and is ended by the next new-line
 > 	character.
 > 
 > Draft C9x changes this wording slightly, but the change doesn't matter
 > for our purposes.
 > 
 >    and "#elsif" does not fit.
 > 
 > I don't see why not.  `#elsif' is a sequence of preprocessing tokens,
 > all alone in a line; this fits the definition quoted above.

Yes, I see.  I don't like it :-), but I agree.  

Since the directive is ifdef'ed out, it can just be a sequence of
pp-tokens that are ignored.

So yes, a warning is appropriate in this case. 

                                             -gavin

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: #elsif
  1998-04-08 23:35     ` #elsif Paul Eggert
@ 1998-04-08 21:20       ` Philippe De Muyter
  1998-04-08 21:13         ` #elsif Paul Eggert
  1998-04-09  3:09         ` #elsif Nick Ing-Simmons
  1998-04-08 21:45       ` #elsif Gavin Romig-Koch
  1998-04-09 17:44       ` #elsif Joern Rennecke
  2 siblings, 2 replies; 13+ messages in thread
From: Philippe De Muyter @ 1998-04-08 21:20 UTC (permalink / raw)
  To: Paul Eggert; +Cc: gavin, gcc2, egcs

> I assume that you do not want to make a special case for `elsif' only.
> (That would be odd; it wouldn't catch other misspellings like `elseif'.)
> But if we report _all_ misspelled directives, then we run afoul of the
> examples that caused RMS to change cccp.c to behave the way it does
> today.
> 
> I wouldn't mind adding the checking to -W (or perhaps to -Wundef); but
> I don't think it should be on by default.
> 
Could you rather warn for every unrecognized directive, even without -W or
-Wall, but have a list of directives accepted by other compilers for which
you would not complain ?

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: #elsif
  1998-04-08 21:20       ` #elsif Philippe De Muyter
@ 1998-04-08 21:13         ` Paul Eggert
  1998-04-09  8:27           ` #elsif Joe Buck
  1998-04-09  3:09         ` #elsif Nick Ing-Simmons
  1 sibling, 1 reply; 13+ messages in thread
From: Paul Eggert @ 1998-04-08 21:13 UTC (permalink / raw)
  To: phdm; +Cc: gcc2, egcs

   Date: Thu, 9 Apr 1998 00:26:05 +0200 (MET DST)
   Cc: gavin@cygnus.com, gcc2@cygnus.com, egcs@cygnus.com

   Could you ... have a list of directives accepted by other compilers
   for which you would not complain ?

I'd rather not do that; it would be too much hassle to maintain.

I just thought of one other useful wrinkle: suppress the warning if
the unknown directive is in a system include file.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: #elsif
  1998-04-07 19:34 ` #elsif Paul Eggert
  1998-04-08  9:27   ` #elsif Joern Rennecke
@ 1998-04-08 15:08   ` Gavin Romig-Koch
  1998-04-08 23:35     ` #elsif Paul Eggert
  1 sibling, 1 reply; 13+ messages in thread
From: Gavin Romig-Koch @ 1998-04-08 15:08 UTC (permalink / raw)
  To: Paul Eggert; +Cc: phdm, gcc2, egcs

Paul Eggert writes:
 >    Date: Tue, 7 Apr 1998 12:08:20 +0200 (MET DST)
 >    From: "Philippe De Muyter" <phdm@macqel.be>
 > 
 >    #if defined(A)
 > 	   printf("A defined\n");
 >    #elsif  defined(B)
 > 	   printf("B undefined\n");
 >    #else   /* nor A nor B */
 > 	   printf("nor A nor B defined\n");
 >    #endif
 > 
 > As I read the C standard, if A is not defined, then GCC is required to
 > accept that program fragment, though I admit the standard's wording is
 > not entirely clear.

I disagree.  While I agree that the standard could be clearer
about this, as I read it, a diagnostic must be issued for the
"elsif".

The syntax of preprocessing directives are clearly spelled out,
and "#elsif" does not fit.  The standard requires a diagnostic
if there is a syntax violation.

There is a passage in 3.8.1, in the context of explaining what
gets skipped by a false directive, "directives are processed
only through the name that determines the directive...".  In
this case the name is "elsif" which does not fit syntacticly.

If you read it differently Paul, show us what you see.

                                        -gavin...

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: #elsif
       [not found] ` <199804080118.SAA26855.cygnus.egcs@shade.twinsun.com>
@ 1998-04-08 15:08   ` Ulrich Drepper
  0 siblings, 0 replies; 13+ messages in thread
From: Ulrich Drepper @ 1998-04-08 15:08 UTC (permalink / raw)
  To: egcs

eggert@twinsun.com (Paul Eggert) writes:

> As I read the C standard, if A is not defined, then GCC is required to
> accept that program fragment, though I admit the standard's wording is
> not entirely clear.

The wording may not, but section 6.8 is very clear.  `control line'
mentions only a fixed amount of possibilities which start with # and
which are handled separately.  All other input is handled as
preprocessing-token and is in case of a not fulfilled #if condition to
be ignored.  The current behaviour is therefore ok.

This also means that #elsif never must be an error but warnings can be
issued if one wants.  But since some compiler manufacturers invent new
# directives it is questionable.  (Of course # directives shouldn't be
introduced but this is something different).

I therefore vote against changing the current behaviour or at least
make the warning not available in -Wall.

-- Uli
---------------.      drepper at gnu.org  ,-.   1325 Chesapeake Terrace
Ulrich Drepper  \    ,-------------------'   \  Sunnyvale, CA 94089 USA
Cygnus Solutions `--' drepper at cygnus.com   `------------------------

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: #elsif
  1998-04-07 19:34 ` #elsif Paul Eggert
@ 1998-04-08  9:27   ` Joern Rennecke
  1998-04-08 15:08   ` #elsif Gavin Romig-Koch
  1 sibling, 0 replies; 13+ messages in thread
From: Joern Rennecke @ 1998-04-08  9:27 UTC (permalink / raw)
  To: Paul Eggert; +Cc: phdm, gcc2, egcs

>    Date: Tue, 7 Apr 1998 12:08:20 +0200 (MET DST)
>    From: "Philippe De Muyter" <phdm@macqel.be>
> 
>    #if defined(A)
> 	   printf("A defined\n");
>    #elsif  defined(B)
> 	   printf("B undefined\n");
>    #else   /* nor A nor B */
> 	   printf("nor A nor B defined\n");
>    #endif
> 
> As I read the C standard, if A is not defined, then GCC is required to
> accept that program fragment, though I admit the standard's wording is
> not entirely clear.
> 
> It might be useful for cpp to warn about skipped, unknown directives
> if -W or -Wall is specified.

IIRC the standard allows any number of warnings, no matter how bogus they
are.  So why not always warn about #elsif - it seems an obvious enough
typo to warn about even if we don't want to warn about unknown directives
in general.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: #elsif
  1998-04-07  6:54 #elsif Philippe De Muyter
@ 1998-04-07 19:34 ` Paul Eggert
  1998-04-08  9:27   ` #elsif Joern Rennecke
  1998-04-08 15:08   ` #elsif Gavin Romig-Koch
       [not found] ` <199804080118.SAA26855.cygnus.egcs@shade.twinsun.com>
  1 sibling, 2 replies; 13+ messages in thread
From: Paul Eggert @ 1998-04-07 19:34 UTC (permalink / raw)
  To: phdm; +Cc: gcc2, egcs

   Date: Tue, 7 Apr 1998 12:08:20 +0200 (MET DST)
   From: "Philippe De Muyter" <phdm@macqel.be>

   #if defined(A)
	   printf("A defined\n");
   #elsif  defined(B)
	   printf("B undefined\n");
   #else   /* nor A nor B */
	   printf("nor A nor B defined\n");
   #endif

As I read the C standard, if A is not defined, then GCC is required to
accept that program fragment, though I admit the standard's wording is
not entirely clear.

It might be useful for cpp to warn about skipped, unknown directives
if -W or -Wall is specified.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* #elsif
@ 1998-04-07  6:54 Philippe De Muyter
  1998-04-07 19:34 ` #elsif Paul Eggert
       [not found] ` <199804080118.SAA26855.cygnus.egcs@shade.twinsun.com>
  0 siblings, 2 replies; 13+ messages in thread
From: Philippe De Muyter @ 1998-04-07  6:54 UTC (permalink / raw)
  To: gcc mailing list, egcs mailing list

The following program compiles without a warning with gcc -W -Wall,
but does not do what the programmer expected.

With the native cc, I get :

	**Error: /tmp/elsif.c: 8: undefined control

-----------------------------------------------------------------------
#include        "stdio.h"
#define B

int main()
        {
#if defined(A)
        printf("A defined\n");
#elsif  defined(B)
        printf("B undefined\n");
#else   /* nor A nor B */
        printf("nor A nor B defined\n");
#endif
	return 0;
        }

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~1998-04-09 17:44 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-04-08  2:13 #elsif SXTHREE
  -- strict thread matches above, loose matches on Subject: below --
1998-04-07  6:54 #elsif Philippe De Muyter
1998-04-07 19:34 ` #elsif Paul Eggert
1998-04-08  9:27   ` #elsif Joern Rennecke
1998-04-08 15:08   ` #elsif Gavin Romig-Koch
1998-04-08 23:35     ` #elsif Paul Eggert
1998-04-08 21:20       ` #elsif Philippe De Muyter
1998-04-08 21:13         ` #elsif Paul Eggert
1998-04-09  8:27           ` #elsif Joe Buck
1998-04-09  3:09         ` #elsif Nick Ing-Simmons
1998-04-08 21:45       ` #elsif Gavin Romig-Koch
1998-04-09 17:44       ` #elsif Joern Rennecke
     [not found] ` <199804080118.SAA26855.cygnus.egcs@shade.twinsun.com>
1998-04-08 15:08   ` #elsif Ulrich Drepper

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).