[cfe-dev] warning request: partial array initialisation

'Chris Hall' chris.hall.list at highwayman.com
Tue Jun 19 11:48:16 PDT 2012


Chandler Carruth wrote (on Tue 19-Jun-2012 at 18:58 +0100):
> On Tue, Jun 19, 2012 at 1:20 AM, Jay Foad <jay.foad at gmail.com> wrote:
>> I'd really like to be able to get a warning when "almost all" elements
>> of an array are initialised:
>>
>>  #define N 8
>>  const int a[N] = { 3, 1, 4, 1, 5, 9, 2 };
>>  warning: some but not all array elements initialised

> Also, this seems really like a coding convention or style you would like
> to enforce, and so I suspect a separate tool would be better suited to it.

I think the requirement is more akin to a static_assert() -- so best handled by some explicit marking of the initialisation.  It could be extended to initialisation of structures, so that if you add a new entry to a structure, the compiler will help you make sure all initialisers are complete.

It could get even more exciting if one could decorate a struct or typedef definition, eg:

  typedef int a_t[N] __attribute__((fully_initialise)) ;

Chris





More information about the cfe-dev mailing list