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]

Re: [patch] struct member warning


| Jeffrey A. Law writes:
| 
| > I made some minor comment clarifications and installed this patch.
| 
| Thanks. Additionally, here is a documentation patch for it.
| 
| *** egcs-19980621/gcc/invoke.texi.bak	Sun Jun 28 22:10:19 1998
| --- egcs-19980621/gcc/invoke.texi	Sun Jun 28 22:13:57 1998
| ***************
| *** 1531,1536 ****
| --- 1531,1546 ----
|   struct t @{ struct s h; int i; @};
|   struct t x = @{ 1, 2, 3 @};
|   @end smallexample
| + 
| + @item
| + An aggregate has an initializer which does not initialize all members.
| + For example, the following code would cause such a warning, because
| + @code{x.h} would be implicitly initialized to zero:
| + 
| + @smallexample
| + struct s @{ int f, g, h; @};
| + struct s x = @{ 3, 4 @};
| + @end smallexample
|   @end itemize
|   
|   @item -Wtraditional

Wouldn't it be better to suppress this warning when the last
parameter is a `0' or NULL ?
I know it is often used to initialize "the rest", ie:

struct s { int f, g, h, i, j; char *p; };
struct s x = { 3, 4, 0 };

should give no warning.

struct s { int f, g, h, i, j; char *p; };
struct s x = { 1, 2, 3, 4, NULL };

should give a warning though.

I agree its kind of fuzzy, but it would be annoying as hell
to be forced to initialize all members with 0 just to get
rid of the warning.

Alternatively, the warning could be suppressed when
both: the last initializing element is 0 and *more* then
three elements are left uninitialized.  Such a case is likely on purpose.

-- 
 Carlo Wood  <carlo@runaway.xs4all.nl>


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