public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* [wish] -Wmissing-array-initializers
@ 2023-02-14 11:33 Alejandro Colomar
  0 siblings, 0 replies; only message in thread
From: Alejandro Colomar @ 2023-02-14 11:33 UTC (permalink / raw)
  To: GCC


[-- Attachment #1.1: Type: text/plain, Size: 886 bytes --]

Hi!

I was wondering if we can have a warning similar to -Wmissing-field-initializers but for arrays.
Here's some example of what kind of code would benefit from this warning:


// foo.c
char *foo[5] = {
    "foo",
    "bar",
    "baz"
    //  oops, accidentally the size doesn't match the actual number of fields
};

// foo.h
extern char *foo[5];


Users should be able to trust that each field will be a valid string,
but we have no way to make sure that the array is initialized with strings.

If the initialization is done through designated initializers [...]=..., or {0}, it wouldn't warn, as with structs.

I couldn't find an open ticket in bugzilla regarding this.  If you want, I could open one.


Does it make sense to you?

Cheers,

Alex

-- 
<http://www.alejandro-colomar.es/>
GPG key fingerprint: A9348594CE31283A826FBDD8D57633D441E25BB5

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-02-14 11:33 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-14 11:33 [wish] -Wmissing-array-initializers Alejandro Colomar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).