This is the mail archive of the gcc-patches@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]

__STDC_VERSION__


The other day when talking about va_copy, Geoff mentioned
__STDC_VERSION__, which it turns out we don't properly
define with -std=iso9899:199409 or -std=iso9899:1999.


r~


PS: option handling really ought to be tidied in cccp.c...


	* cccp.c (main): Define __STDC_VERSION__ as necessary.
	* cppinit.c (cpp_handle_option): Likewise.

	* ginclude/stdarg.h (va_copy): Use __STDC_VERSION__ to
	determine when to define.

Index: gcc/cccp.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cccp.c,v
retrieving revision 1.88
diff -u -p -d -r1.88 cccp.c
--- cccp.c	1999/12/14 16:05:23	1.88
+++ cccp.c	1999/12/19 04:28:17
@@ -1264,7 +1264,7 @@ main (argc, argv)
      progname need to be set first, in case a diagnostic is issued.  */
      
   pend_files = (char **) xmalloc (argc * sizeof (char *));
-  pend_defs = (char **) xmalloc (argc * sizeof (char *));
+  pend_defs = (char **) xmalloc ((2 * argc) * sizeof (char *));
   pend_undefs = (char **) xmalloc (argc * sizeof (char *));
   pend_assertions = (char **) xmalloc (argc * sizeof (char *));
   pend_includes = (char **) xmalloc (argc * sizeof (char *));
@@ -1284,7 +1284,7 @@ main (argc, argv)
   cplusplus_comments = 1;
 
   bzero ((char *) pend_files, argc * sizeof (char *));
-  bzero ((char *) pend_defs, argc * sizeof (char *));
+  bzero ((char *) pend_defs, (2 * argc) * sizeof (char *));
   bzero ((char *) pend_undefs, argc * sizeof (char *));
   bzero ((char *) pend_assertions, argc * sizeof (char *));
   bzero ((char *) pend_includes, argc * sizeof (char *));
@@ -1457,7 +1457,7 @@ main (argc, argv)
 	  {
 	    cplusplus = 0, cplusplus_comments = 0, c89 = 1, c9x = 0, objc = 0;
 	    no_trigraphs = 0;
-	    pend_defs[i] = "__STRICT_ANSI__=199000";
+	    pend_defs[2*i] = "__STRICT_ANSI__";
 	  }
 	else if (! strcmp (argv[i], "-lang-c++"))
 	  cplusplus = 1, cplusplus_comments = 1, c89 = 0, c9x = 0, objc = 0;
@@ -1484,19 +1484,21 @@ main (argc, argv)
 		 || !strcmp (argv[i], "-std=gnu99"))
 	  {
 	    cplusplus = 0, cplusplus_comments = 1, c89 = 0, c9x = 1, objc = 0;
+	    pend_defs[2*i+1] = "__STDC_VERSION__=199901L";
 	  }
 	else if (!strcmp (argv[i], "-std=iso9899:1990")
 		 || !strcmp (argv[i], "-std=c89"))
 	  {
 	    cplusplus = 0, cplusplus_comments = 0, c89 = 1, c9x = 0, objc = 0;
 	    no_trigraphs = 0;
-	    pend_defs[i] = "__STRICT_ANSI__=199000";
+	    pend_defs[2*i] = "__STRICT_ANSI__";
 	  }
 	else if (!strcmp (argv[i], "-std=iso9899:199409"))
 	  {
 	    cplusplus = 0, cplusplus_comments = 0, c89 = 1, c9x = 0, objc = 0;
 	    no_trigraphs = 0;
-	    pend_defs[i] = "__STRICT_ANSI__=199409";
+	    pend_defs[2*i] = "__STRICT_ANSI__";
+	    pend_defs[2*i+1] = "__STDC_VERSION__=199409L";
 	  }
         else if (!strcmp (argv[i], "-std=iso9899:199x")
 		 || !strcmp (argv[i], "-std=iso9899:1999")
@@ -1505,7 +1507,8 @@ main (argc, argv)
 	  {
 	    cplusplus = 0, cplusplus_comments = 1, c89 = 0, c9x = 1, objc = 0;
 	    no_trigraphs = 0;
-	    pend_defs[i] = "__STRICT_ANSI__=199900";
+	    pend_defs[2*i] = "__STRICT_ANSI__";
+	    pend_defs[2*i+1] = "__STDC_VERSION__=199901L";
 	  }
 	break;
 
@@ -1655,11 +1658,11 @@ main (argc, argv)
 
       case 'D':
 	if (argv[i][2] != 0)
-	  pend_defs[i] = argv[i] + 2;
+	  pend_defs[2*i] = argv[i] + 2;
 	else if (i + 1 == argc)
 	  fatal ("Macro name missing after -D option");
 	else
-	  i++, pend_defs[i] = argv[i];
+	  i++, pend_defs[2*i] = argv[i];
 	break;
 
       case 'A':
@@ -1680,7 +1683,7 @@ main (argc, argv)
 	       that were passed automatically in from GCC.  */
 	    int j;
 	    for (j = 0; j < i; j++)
-	      pend_defs[j] = pend_assertions[j] = 0;
+	      pend_defs[2*j] = pend_assertions[j] = 0;
 	  } else {
 	    pend_assertions[i] = p;
 	    pend_assertion_options[i] = "-A";
@@ -1805,10 +1808,15 @@ main (argc, argv)
         output_line_directive (fp, &outbuf, 0, same_file);
       make_undef (pend_undefs[i], &outbuf);
     }
-    if (pend_defs[i]) {
+    if (pend_defs[2*i]) {
       if (debug_output)
         output_line_directive (fp, &outbuf, 0, same_file);
-      make_definition (pend_defs[i]);
+      make_definition (pend_defs[2*i]);
+    }
+    if (pend_defs[2*i+1]) {
+      if (debug_output)
+        output_line_directive (fp, &outbuf, 0, same_file);
+      make_definition (pend_defs[2*i+1]);
     }
     if (pend_assertions[i])
       make_assertion (pend_assertion_options[i], pend_assertions[i]);
Index: gcc/cppinit.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cppinit.c,v
retrieving revision 1.27
diff -u -p -d -r1.27 cppinit.c
--- cppinit.c	1999/12/14 16:05:23	1.27
+++ cppinit.c	1999/12/19 04:28:17
@@ -1331,7 +1331,7 @@ cpp_handle_option (pfile, argc, argv)
 	    opts->cplusplus = 0, opts->cplusplus_comments = 0;
 	    opts->c89 = 1, opts->c9x = 0, opts->objc = 0;
 	    opts->trigraphs = 1;
-	    new_pending_define (opts, "__STRICT_ANSI__=199000");
+	    new_pending_define (opts, "__STRICT_ANSI__");
 	  }
 	if (! strcmp (argv[i], "-lang-c++"))
 	  opts->cplusplus = 1, opts->cplusplus_comments = 1, opts->c89 = 0,
@@ -1365,6 +1365,7 @@ cpp_handle_option (pfile, argc, argv)
 	  {
 	    opts->cplusplus = 0, opts->cplusplus_comments = 1;
 	    opts->c89 = 0, opts->c9x = 1, opts->objc = 0;
+	    new_pending_define (opts, "__STDC_VERSION__=199901L");
 	  }
 	else if (!strcmp (argv[i], "-std=iso9899:1990")
 		 || !strcmp (argv[i], "-std=c89"))
@@ -1372,14 +1373,15 @@ cpp_handle_option (pfile, argc, argv)
 	    opts->cplusplus = 0, opts->cplusplus_comments = 0;
 	    opts->c89 = 1, opts->c9x = 0, opts->objc = 0;
 	    opts->trigraphs = 1;
-	    new_pending_define (opts, "__STRICT_ANSI__=199000");
+	    new_pending_define (opts, "__STRICT_ANSI__");
 	  }
 	else if (!strcmp (argv[i], "-std=iso9899:199409"))
 	  {
 	    opts->cplusplus = 0, opts->cplusplus_comments = 0;
 	    opts->c89 = 1, opts->c9x = 0, opts->objc = 0;
 	    opts->trigraphs = 1;
-	    new_pending_define (opts, "__STRICT_ANSI__=199409");
+	    new_pending_define (opts, "__STRICT_ANSI__");
+	    new_pending_define (opts, "__STDC_VERSION__=199409L");
 	  }
 	else if (!strcmp (argv[i], "-std=iso9899:199x")
 		 || !strcmp (argv[i], "-std=iso9899:1999")
@@ -1389,7 +1391,8 @@ cpp_handle_option (pfile, argc, argv)
 	    opts->cplusplus = 0, opts->cplusplus_comments = 1;
 	    opts->c89 = 0, opts->c9x = 1, opts->objc = 0;
 	    opts->trigraphs = 1;
-	    new_pending_define (opts, "__STRICT_ANSI__=199900");
+	    new_pending_define (opts, "__STRICT_ANSI__");
+	    new_pending_define (opts, "__STDC_VERSION__=199901L");
 	  }
 	break;
 
Index: gcc/ginclude/stdarg.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/ginclude/stdarg.h,v
retrieving revision 1.12
diff -u -p -d -r1.12 stdarg.h
--- stdarg.h	1999/12/14 16:05:23	1.12
+++ stdarg.h	1999/12/19 04:28:18
@@ -54,7 +54,7 @@ typedef __builtin_va_list __gnuc_va_list
 #define va_start(v,l)	__builtin_stdarg_start(&(v),l)
 #define va_end		__builtin_va_end
 #define va_arg		__builtin_va_arg
-#if defined(__STRICT_ANSI__) && __STRICT_ANSI__ + 0 < 199900
+#if !defined(__STRICT_ANSI__) || __STDC_VERSION__ + 0 >= 199900L
 #define va_copy(d,s)	__builtin_va_copy(&(d),(s))
 #endif
 #define __va_copy(d,s)	__builtin_va_copy(&(d),(s))


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