From 7de9cc38c319240807a7942d7cbd1b0c1933a766 Mon Sep 17 00:00:00 2001 From: "Kaveh R. Ghazi" Date: Fri, 7 Jul 2000 14:29:03 +0000 Subject: [PATCH] system.h (UNION_INIT_ZERO): New macro for initializing union members in structs. * system.h (UNION_INIT_ZERO): New macro for initializing union members in structs. * cpplex.c (placemarker_token, eof_token): Use UNION_INIT_ZERO. From-SVN: r34904 --- gcc/ChangeLog | 7 +++++++ gcc/cpplex.c | 4 ++-- gcc/system.h | 10 ++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index e53d1e53bf9..bac2fdc1ee2 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2000-07-07 Kaveh R. Ghazi + + * system.h (UNION_INIT_ZERO): New macro for initializing union + members in structs. + + * cpplex.c (placemarker_token, eof_token): Use UNION_INIT_ZERO. + 2000-07-07 Neil Booth * cpp.texi: Update. diff --git a/gcc/cpplex.c b/gcc/cpplex.c index 5f1707ad27e..24e4712d561 100644 --- a/gcc/cpplex.c +++ b/gcc/cpplex.c @@ -1935,8 +1935,8 @@ 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}}; +static const cpp_token placemarker_token = {0, 0, CPP_PLACEMARKER, 0 UNION_INIT_ZERO}; +static const cpp_token eof_token = {0, 0, CPP_EOF, 0 UNION_INIT_ZERO}; #define IS_ARG_CONTEXT(c) ((c)->flags & CONTEXT_ARG) #define CURRENT_CONTEXT(pfile) ((pfile)->contexts + (pfile)->cur_context) diff --git a/gcc/system.h b/gcc/system.h index ab2cfa7d627..d5fb4d23185 100644 --- a/gcc/system.h +++ b/gcc/system.h @@ -600,4 +600,14 @@ extern void abort PARAMS ((void)); #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) #endif +/* Traditional C cannot initialize union members of structs. Provide + a macro which expands appropriately to handle it. This only works + if you intend to initalize the union member to zero since it relies + on default initialization to zero in the traditional C case. */ +#ifdef __STDC__ +#define UNION_INIT_ZERO , {0} +#else +#define UNION_INIT_ZERO +#endif + #endif /* __GCC_SYSTEM_H__ */