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 to supress trailing missing initializer warnings


| Hi,
| egcs currently warns when an aggregate initializer does not initialize
| all the members. I found this annoying (and did report it as a bug
| http://www.cygnus.com/ml/egcs-bugs/1998-Jul/0031.html). There was
| previously some discussion on the patches list about the patch which
| introduced the check
| (http://www.cygnus.com/ml/egcs-patches/1998-Jun/0421.html). The
| suggestion was made to inhibit the warning, if the last initialized
| member was zero, although some reservations were expressed about that.
| 
| This patch only warns when the last supplied initializer is not a
| constant expression of value zero (integral or null pointer), or
| -Wuninitialized is also given. Thus you get the current egcs behaviour
| by supplying -W -Wuninitialized, rather than just -W. Even though
| implicit initialization to zero is different to uninitialized, using
| -Wuninitialized to trigger the picky behaviour seems a reasonable thing
| to do in the abscense of adding a completely separate warning flag
| (opinions may vary ...).
| 
| Files altered gcc/cp/ChangeLog, gcc/cp/typeck2.c, gcc/invoke.texi
| 
| Here is a test source file you can use to show the behaviours,
| --begin missinit.ii
| struct S1 { int a; int b; int c;};
| struct S2 { void *a; int b; int c;};
| struct S3 { S1 a; int b; int c;};
| static S1 s1a = {0};
| static S1 s1b = {1};
| static S2 s2a = {0};
| static S2 s2b = {__null};
| static S2 s2c = {&s2a};
| static S3 s3a = {{0}};
| static S3 s3b = {{0}, 0};
| --end missinit.ii

I recall that I suggested to give the warning if less then
three variables where left uninitialized.

Example:

struct S1 { int a; int b; int c;};
static S1 s1a = {0};

gives a warning, you need:

static S1 s1a = {0, 0, 0};

But:

struct S1 { int a; int b; int c; int d;};
static S1 s1a = {0};

gives no warning, because three (or more) elements are
left uninitialized after the 0 (or NULL).

I think this make it less likely that someone by accident forgets
to initialize one or two elements, and the last element is
by coincidence to be initialized with a zero.

Although this feels like a fuzzy "solution", it is NOT
worse: You only give MORE warnings.  And I think it will
cover 90% of the cases that you really made an error
in the number of elements you did initialize.  Ie, it is
ten times as good :).

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


PS More practical examples are:

u_char convert2n[NUMNICKMAXCHAR + 1] = {
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0,52,53,54,55,56,57,58,59,60,61, 0, 0,
  0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,
 15,16,17,18,19,20,21,22,23,24,25,62, 0,63, 0, 0, 0,26,27,28,
 29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,
 49,50,51, 0, 0, 0, 0, 0, 0
};

Did I forget one or not?

And

#define MAX_NEURONS 1024
struct AI_tab *AI_table[MAX_NEURONS] = { first_neuron, NULL };



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