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

Traditional C chokes on struct/union initialization in new cpplex.c


Hi Zack,

	I had some trouble compiling the overhauled cpplex.c on sunos4
using its K&R cc compiler.  I get:

 > "../../egcs-CVS20000705/gcc/cpplex.c", line 1938: operands of = have
 > 				       incompatible types
 > "../../egcs-CVS20000705/gcc/cpplex.c", line 1939: operands of = have
 > 				       incompatible types


The problem occurs on these two lines from cpplex.c:

 > static const cpp_token placemarker_token = {0, 0, CPP_PLACEMARKER, 0, {0}};
 > static const cpp_token eof_token = {0, 0, CPP_EOF, 0, {0}};

Based on some experimentation, it appears to me that traditional C
cannot initialize a union member of a struct.  I tried getting it to
work by playing with braces, etc., but no luck.

If I take out the {0} entirely, then default initialization to zero
works.  However I still want to have the {0} appear for gcc so we
don't get missing member initialization warnings.

I hacked up this patch and got midway through stage2 so far.  Assuming
bootstrap succeeds, ok to install?

		--Kaveh


2000-07-05  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>

	* cpplex.c (placemarker_token, eof_token): Don't initialize struct
	union member in traditional C.

diff -rup ../egcs-CVS20000705/gcc/cpplex.c egcs-CVS20000705/gcc/cpplex.c
--- ../egcs-CVS20000705/gcc/cpplex.c	Wed Jul  5 05:43:15 2000
+++ egcs-CVS20000705/gcc/cpplex.c	Wed Jul  5 16:05:21 2000
@@ -1935,8 +1935,15 @@ spell_token (pfile, token, buffer)
 
 /* Macro expansion algorithm.  TODO.  */
 
-static const cpp_token placemarker_token = {0, 0, CPP_PLACEMARKER, 0, {0}};
-static const cpp_token eof_token = {0, 0, CPP_EOF, 0, {0}};
+/* Traditional C cannot initialize union members of structs.  */
+#ifdef ANSI_PROTOTYPES
+#define UNION_INIT , {0}
+#else
+#define UNION_INIT
+#endif
+
+static const cpp_token placemarker_token = {0, 0, CPP_PLACEMARKER, 0 UNION_INIT};
+static const cpp_token eof_token = {0, 0, CPP_EOF, 0 UNION_INIT};
 
 #define IS_ARG_CONTEXT(c) ((c)->flags & CONTEXT_ARG)
 #define CURRENT_CONTEXT(pfile) ((pfile)->contexts + (pfile)->cur_context)

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