C standard selection

Ulrich Drepper drepper@cygnus.com
Fri Nov 6 23:07:00 GMT 1998


Hi,

Could we please add the patch below (or a similar patch) soon, before
the horrible -flang-isoc9x option is in wider use?  Sorry Mark, but
this option is really the wrong approach.

The patch is based on a proposal by Paul Eggert when we discussed this
a long time ago.  It is compatible with old practice (i.e., -std=gnu
translates to -lang-c for cpp etc) and leaves room for extensions.

I've also made two further changes:

- the ISO C 9x extensions are enabled for GNU C.  It always was the
  case that GNU C means all extensions included.

- I've added a first tiny change to the parser to handle the differences
  in ISO C 9x (comma at the end of enum definitions are allowed now).
  More to come.


Paul Eggert promised :-) to handle the preprocessor changes so I hope
we get the appropriate changes soon.

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

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Index: c-decl.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/c-decl.c,v
retrieving revision 1.51
diff -u -b -d -r1.51 c-decl.c
--- c-decl.c	1998/10/21 09:53:20	1.51
+++ c-decl.c	1998/11/07 06:38:20
@@ -470,7 +470,7 @@
 
 /* Nonzero means use the ISO C9x dialect of C.  */
 
-int flag_isoc9x = 0;
+int flag_isoc9x = 1;
 
 /* Nonzero means that we have builtin functions, and main is an int */
 
@@ -652,8 +652,54 @@
       flag_traditional = 0;
       flag_writable_strings = 0;
     }
-  else if (!strcmp (p, "-flang-isoc9x"))
+  else if (!strncmp (p, "-std=", 5))
+    {
+      /* Select the appropriate language standard.  We currently
+	 recognize:
+	 -std=iso9899:1990	same as -ansi
+	 -std=c			default
+	 -std=gnu		same as -std=c
+	 -std=iso9899:199409	ISO C as modified in amend. 1
+	 -std=iso9899:199x	ISO C 9x
+	 -std=c9x		same as -std=iso9899:199x
+      */
+      const char *argstart = &p[5];
+
+      if (!strcmp (argstart, "c89"))
+	{
+	iso_1990:
+	  flag_traditional = 0;
+	  flag_writable_strings = 0;
+	  flag_no_asm = 1;
+	  flag_no_nonansi_builtin = 1;
+	  flag_isoc9x = 0;
+	}
+      else if (!strcmp (argstart, "c"))
+	{
+	  flag_traditional = 0;
+	  flag_writable_strings = 0;
+	  flag_no_asm = 0;
+	  flag_no_nonansi_builtin = 0;
     flag_isoc9x = 1;
+	}
+      else if (!strcmp (argstart, "iso9899:199409"))
+	{
+	  /* FIXME Currently the differences to ISO C 1990 are not
+	     supported.  */
+	  goto iso_1990;
+	}
+      else if (!strcmp (argstart, "iso9899:199x")
+	       || !strcmp (argstart, "c9x"))
+	{
+	  flag_traditional = 0;
+	  flag_writable_strings = 0;
+	  flag_no_asm = 1;
+	  flag_no_nonansi_builtin = 1;
+	  flag_isoc9x = 1;
+	}
+      else
+	error ("unknown C standard `%s'", argstart);
+    }
   else if (!strcmp (p, "-fdollars-in-identifiers"))
     dollars_in_ident = 1;
   else if (!strcmp (p, "-fno-dollars-in-identifiers"))
Index: c-parse.y
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/c-parse.y,v
retrieving revision 1.10
diff -u -b -d -r1.10 c-parse.y
--- c-parse.y	1998/10/21 09:53:30	1.10
+++ c-parse.y	1998/11/07 06:38:21
@@ -1338,7 +1338,8 @@
 maybecomma_warn:
 	  /* empty */
 	| ','
-		{ if (pedantic) pedwarn ("comma at end of enumerator list"); }
+		{ if (pedantic && !flag_isoc9x)
+		    pedwarn ("comma at end of enumerator list"); }
 	;
 
 component_decl_list:
Index: gcc.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/gcc.c,v
retrieving revision 1.65
diff -u -b -d -r1.65 gcc.c
--- gcc.c	1998/11/02 07:20:47	1.65
+++ gcc.c	1998/11/07 06:38:24
@@ -614,13 +614,14 @@
   {".c", {"@c"}},
   {"@c",
    {
-#if USE_CPPLIB
-     "%{E|M|MM:cpp -lang-c%{ansi:89} %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
+#if USE_CPLIB
+     "%{E|M|MM:cpp -lang-%{std=*:%*}%{!std=*:c%{ansi:89}}\
+        %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
 	%{C:%{!E:%eGNU C does not support -C without using -E}}\
 	%{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
         -undef -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
-	%{ansi:-trigraphs -D__STRICT_ANSI__}\
-	%{!undef:%{!ansi:%p} %P} %{trigraphs} \
+	%{ansi|std=*:-trigraphs -D__STRICT_ANSI__}\
+	%{!undef:%{!ansi:%{!std=*:%p}} %P} %{trigraphs} \
         %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
         %{traditional} %{ftraditional:-traditional}\
         %{traditional-cpp:-traditional}\
@@ -628,15 +629,16 @@
 	%{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
         %i %{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}}\n}\
       %{!E:%{!M:%{!MM:cc1 %i %1 \
-                  -lang-c%{ansi:89} %{nostdinc*} %{A*} %{I*} %I\
+                  -lang-%{std=*:%*}%{!std=*:c%{ansi:89}}\
+                  %{nostdinc*} %{A*} %{I*} %I\
                   %{!Q:-quiet} -dumpbase %b.c %{d*} %{m*} %{a*}\
                   %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
                   -undef -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
-                  %{ansi:-trigraphs -D__STRICT_ANSI__}\
-                  %{!undef:%{!ansi:%p} %P} %{trigraphs} \
+                  %{ansi|std=*:-trigraphs -D__STRICT_ANSI__}\
+                  %{!undef:%{!ansi:%{!std=*:%p}} %P} %{trigraphs} \
                   %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
                   %{H} %C %{D*} %{U*} %{i*} %Z\
-                  %{ftraditional:-traditional}\
+                  %{ftraditional:-traditional} \
                   %{traditional-cpp:-traditional}\
 		  %{traditional} %{v:-version} %{pg:-p} %{p} %{f*}\
 		  %{aux-info*}\
@@ -649,12 +651,13 @@
                      %{!pipe:%g.s} %A\n }}}}"
   }},
 #else /* ! USE_CPPLIB */
-    "cpp -lang-c%{ansi:89} %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
+    "cpp -lang-%{std=*:%*}%{!std=*:c%{ansi:89}}\
+        %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
 	%{C:%{!E:%eGNU C does not support -C without using -E}}\
 	%{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
         -undef -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
-	%{ansi:-trigraphs -D__STRICT_ANSI__}\
-	%{!undef:%{!ansi:%p} %P} %{trigraphs} \
+	%{ansi|std=*:-trigraphs -D__STRICT_ANSI__}\
+	%{!undef:%{!ansi:%{!std=*:%p}} %P} %{trigraphs} \
         %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
         %{traditional} %{ftraditional:-traditional}\
         %{traditional-cpp:-traditional}\
@@ -663,7 +666,7 @@
         %i %{!M:%{!MM:%{!E:%{!pipe:%g.i}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n",
    "%{!M:%{!MM:%{!E:cc1 %{!pipe:%g.i} %1 \
 		   %{!Q:-quiet} -dumpbase %b.c %{d*} %{m*} %{a*}\
-		   %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi} \
+		   %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi} %{std=*} \
 		   %{traditional} %{v:-version} %{pg:-p} %{p} %{f*}\
 		   %{aux-info*}\
 		   %{--help:--help} \
@@ -675,12 +678,13 @@
   }},
 #endif /* ! USE_CPPLIB */
   {"-",
-   {"%{E:cpp -lang-c%{ansi:89} %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
+   {"%{E:cpp -lang-%{std=*:%*}%{!std=*:c%{ansi:89}}\
+        %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
 	%{C:%{!E:%eGNU C does not support -C without using -E}}\
 	%{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
         -undef -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
-	%{ansi:-trigraphs -D__STRICT_ANSI__}\
-	%{!undef:%{!ansi:%p} %P} %{trigraphs}\
+	%{ansi|std=*:-trigraphs -D__STRICT_ANSI__}\
+	%{!undef:%{!ansi:%{!std=*:%p}} %P} %{trigraphs}\
         %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
         %{traditional} %{ftraditional:-traditional}\
         %{traditional-cpp:-traditional}\
@@ -720,8 +724,8 @@
 	%{C:%{!E:%eGNU C does not support -C without using -E}}\
 	 %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
         -undef -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
-	 %{ansi:-trigraphs -D__STRICT_ANSI__}\
-	%{!undef:%{!ansi:%p} %P} %{trigraphs}\
+        %{ansi|std=*:-trigraphs -D__STRICT_ANSI__}\
+	%{!undef:%{!ansi:%{!std=*:%p}} %P} %{trigraphs}\
         %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
         %{traditional} %{ftraditional:-traditional}\
         %{traditional-cpp:-traditional}\
@@ -908,6 +912,7 @@
    {"--silent", "-q", 0},
    {"--specs", "-specs=", "aj"},
    {"--static", "-static", 0},
+   {"--std", "-std=", "aj"},
    {"--symbolic", "-symbolic", 0},
    {"--target", "-b", "a"},
    {"--trace-includes", "-H", 0},
@@ -2514,6 +2519,7 @@
   printf ("  -save-temps              Do not delete intermediate files\n");
   printf ("  -pipe                    Use pipes rather than intermediate files\n");
   printf ("  -specs=<file>            Override builtin specs with the contents of <file>\n");
+  printf ("  -std=<standard>          Assume that the input sources are for <standard>\n");
   printf ("  -B <directory>           Add <directory> to the compiler's search paths\n");
   printf ("  -b <machine>             Run gcc for target <machine>, if installed\n");
   printf ("  -V <version>             Run gcc version number <version>, if installed\n");
@@ -2894,6 +2900,37 @@
 	    user_specs_head = user;
 	  user_specs_tail = user;
 	}
+      else if (strncmp (argv[i], "-std=", 5) == 0)
+	{
+	  /* Test whether it is any of the supported standards.
+	     So far this option is only used for selecting C
+	     dialects and standards.  */
+	  char *arg = &argv[i][5];
+
+	  if (strcmp (arg, "c89") == 0
+	      || strcmp (arg, "iso9899:199409") == 0
+	      || strcmp (arg, "iso9899:199x") == 0
+	      || strcmp (arg, "c") == 0)
+	    goto normal_switch;
+
+	  /* We recognize a few more options but translate them.  */
+	  if (strcmp (arg, "iso9899:1990") == 0)
+	    {
+	      argv[i] = (char *) "-std=c89";
+	      goto normal_switch;
+	    }
+	  if (strcmp (arg, "c9x") == 0)
+	    {
+	      argv[i] = (char *) "-std=iso9899:199x";
+	      goto normal_switch;
+	    }
+	  if (strcmp (arg, "gnu") == 0)
+	    {
+	      argv[i] = (char *) "-std=c";
+	      goto normal_switch;
+	    }
+	  fatal ("unknown standard `%s'", arg);
+	}
       else if (argv[i][0] == '-' && argv[i][1] != 0)
 	{
 	  register char *p = &argv[i][1];
Index: toplev.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/toplev.c,v
retrieving revision 1.125
diff -u -b -d -r1.125 toplev.c
--- toplev.c	1998/11/04 22:49:18	1.125
+++ toplev.c	1998/11/07 06:38:26
@@ -950,6 +955,7 @@
   { "-ansi", "Compile just for ANSI C" },
   { "-fallow-single-precision",
     "Do not promote floats to double if using -traditional" },
+  { "-std= ", "Determine C language standard"},
 
   { "-fsigned-bitfields", "" },
   { "-funsigned-bitfields","Make bitfields by unsigned by default" },
@@ -964,7 +970,6 @@
   { "-traditional", "Attempt to support traditional K&R style C"},
   { "-fnotraditional", "" },
   { "-fno-traditional", "" },
-  { "-flang-isoc9x", "Enable C9X features"},
 
   { "-fasm", "" },
   { "-fno-asm", "Do not recognise the 'asm' keyword" },



More information about the Gcc-patches mailing list