By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,443 Members | 1,409 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,443 IT Pros & Developers. It's quick & easy.

"Partially elided initialisation" on initialising 2-D array

P: n/a
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

Dec 20 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
ma**********@thales-is.com wrote:
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
Dec 20 '06 #2

P: n/a
ma**********@thales-is.com writes:
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.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Dec 20 '06 #3

P: n/a
On Wed, 20 Dec 2006 15:09:40 -0800, Keith Thompson <ks***@mib.org>
wrote:
>ma**********@thales-is.com writes:
>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.

--
Al Balmer
Sun City, AZ
Dec 21 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.