"Partially elided initialisation" on initialising 2-D array

M

mark.bergman

Running lint on code initialising a local 2-D array gives a warning.

void f(void)
{
int a[5][3] = { 0 };
...

lint gives "warning: Partially elided initialisation..."

Should this be happening, and what does it mean (the warning does not
occur for 1-D array)?

[Running "lint -std1 -u -x a.c" on Tru64 platform]

TIA
Mark
 
R

Richard Bos

Running lint on code initialising a local 2-D array gives a warning.

void f(void)
{
int a[5][3] = { 0 };
...

lint gives "warning: Partially elided initialisation..."

Should this be happening, and what does it mean (the warning does not
occur for 1-D array)?

Try using one set of braces for each dimension:

int a[5][3] = { {0} };

That will probably shut lint up. The effect of the code should be the
same either way, since non-initialised members of a partly-initialised
compound object should be initialised as if explicitly given a 0 value.
IOW, the warning is not entirely bogus (what it says is true), but not
very meaningful (what it says is not a problem).

Richard
 
K

Keith Thompson

Running lint on code initialising a local 2-D array gives a warning.

void f(void)
{
int a[5][3] = { 0 };
...

lint gives "warning: Partially elided initialisation..."

Should this be happening, and what does it mean (the warning does not
occur for 1-D array)?

[Running "lint -std1 -u -x a.c" on Tru64 platform]

"{ 0 }" is a perfectly good way to specify initializing something to
all zeros. (Note: it specifies logical zero values for each
component, not necessarily all-bits-zero; pointers will be set to
null, and floating-point numbers to 0.0.)

On the other hand, a C implementation is free to issue any diagnostics
it likes, for any reason:

warning: No errors detected on this line
warning: Danger, Will Robinson!

And lint isn't even a C implementation.

You might complain to the authors of your particular lint about the
warning for this correct and idiomatic construct, but there's no
conformance issue.
 
A

Al Balmer

Running lint on code initialising a local 2-D array gives a warning.

void f(void)
{
int a[5][3] = { 0 };
...

lint gives "warning: Partially elided initialisation..."

Should this be happening, and what does it mean (the warning does not
occur for 1-D array)?

[Running "lint -std1 -u -x a.c" on Tru64 platform]

"{ 0 }" is a perfectly good way to specify initializing something to
all zeros. (Note: it specifies logical zero values for each
component, not necessarily all-bits-zero; pointers will be set to
null, and floating-point numbers to 0.0.)

On the other hand, a C implementation is free to issue any diagnostics
it likes, for any reason:

warning: No errors detected on this line
warning: Danger, Will Robinson!

And lint isn't even a C implementation.

You might complain to the authors of your particular lint about the
warning for this correct and idiomatic construct, but there's no
conformance issue.

On HP-UX, we get a warning saying that partially elided
initializations may be handled differently when compiled in ANSI mode.
I suppose that means that their pre-ANSI compiler did something
non-standard.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top