This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: cpplib: Language defaults


On Sat, Nov 18, 2000 at 07:45:03PM +0000, Neil Booth wrote:
> Nathan noticed that cc1plus does not default to -lang-cpp for the
> integrated preprocessor (the same would be true for the objc front
> end), meaning he had to pass it on the command line.
> 
> I've been looking at the best way to solve this.  My approach is:-
> 
> o Have a function in cppinit.c called set_lang.  This is called from
>   cpp_start_read.  It, and cpp_start_read in turn, take a LANG enum,
>   which is from the list below:
> 
>   enum c_lang {LANG_GNU89 = 0, LANG_GNU99, LANG_STD89, LANG_STD94,
>        LANG_STD99, LANG_CPP, LANG_OBJC, LANG_OBJCPP, LANG_ASM};

I like this idea.  Your implementation is a tad confusing.  I think it
would be more readable as a case statement:

  case LANG_GNU89:
     a = 1; b = 1; ...
     break;

even if this does mean it's longer.  Also, you ought to distinguish
between strictly conforming C++ and extended C++ modes.  This matters
at least for trigraph interpretation.  We ought to have a -std=c++98
switch.

We have all these other identifiers with CPP in them that have nothing
to do with C++.  Therefore I think the enum should use CXX instead of
CPP.  Furthermore, the _GNU?? and _STD?? constants should indicate
explicitly that they are C.

We already have an enumeration that sort-of does this: in c-common.h,

typedef enum c_language_kind
{
  clk_c,           /* A dialect of C: K&R C, ANSI/ISO C89, C2000,
                       etc. */
  clk_cplusplus,   /* ANSI/ISO C++ */
  clk_objective_c  /* Objective C */
}
c_language_kind;

Perhaps extend that rather than inventing yet another set of constants?

> 1) __STRICT_ANSI__ was only being set for C89 and C94.  Surely this
>   should be done for C99 too?  Assuming it should, I've fixed this
>   below.

Yes, I think it should (in strictly conforming mode).

> 2) There is no definition of __STDC_VERSION__ for C89 or GNU89.  There
>    is for C94, C99 and GNU99.  I've left this as it is.

The C89 standard did not specify __STDC_VERSION__, it was added in
Amendment 1.

> 3) Whereas it seems we default to GNU89 if not told otherwise, GNU89
>    sets the C89 flag to 1.  We were not doing this by default before.
>    I've "fixed" this below.

CPP_OPTION (pfile, c89) is not used consistently.  It's got three
uses:

  File      Line
1 cppexp.c   208 if (CPP_OPTION (pfile, c89) && sufftab[i].l == 2)
2 cpphash.h   29 || (((prevc) == 'p' || (prevc) == 'P') 
			&& !CPP_OPTION (pfile, c89))))
1 cpplex.c  1010 if (CPP_OPTION (pfile, c89) && CPP_PEDANTIC (pfile)

In the first instance it means 'unextended C89'.  In the second two,
it means 'not C99'.  This needs to get fixed.

>       CPP_OPTION (pfile, dollars_in_ident) = 1;

This should only be set in extended mode.  And do we really want to
turn it off in assembly mode?

zw

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]