public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: Array Initialization warnings
@ 2002-04-20  6:58 David Stroupe
  2002-04-20  7:06 ` Michal Liptak
  0 siblings, 1 reply; 10+ messages in thread
From: David Stroupe @ 2002-04-20  6:58 UTC (permalink / raw)
  To: gcc-help

>Hi David,
>
> The compiler is quite right, your initialiser is for
>an int JPEG_MRK_NTSC[16].
>
>Try something like;
>
>int JPEG_MRK_NTSC[4][4] =
> {
> {0x01, 0x02, 0x03, 0x04},
> {0x05, 0x06, 0x07, 0x08},
> {0x09, 0x0a, 0x0b, 0x0c},
> {0x0d, 0x0e, 0x0f, 0x00}
> };
>
>yours sincerely,
>
>bjorn

Thanks bjorn, indeed that eliminates the warnings and your explanation makes perfect sense.  Is it an accident...or just lucky,
that the array members are initialized correctly regardless of the way that I write the code?  I am porting this code from 
windows and the same warning did not appear in the msvc compiler.  Is this a compiler dependent issue and am I just asking
for trouble if the brackets are left out?

Thanks again!!

David Stroupe wrote:
> 
> When I compile this line of code
> 
> int JPEG_MRK_NTSC[4][4] =
> {
> 0x01, 0x02, 0x03, 0x04,
> 0x05, 0x06, 0x07, 0x08,
> 0x09, 0x0a, 0x0b, 0x0c,
> 0x0d, 0x0e, 0x0f, 0x00
> };
> 
>  with the -Wall option, I get the following warnings
> 
> vis.c:264: warning: missing braces around initializer
> vis.c:264: warning: (near initialization for `JPEG_MRK_NTSC[0]')
> 
> If I look at the values of the array members during execution, they are
> correct.
> 
> Is this array really being initialized correctly?
> Are the warnings correct?
> 
> Is there a way to 'turn off' these particular warnings with a compiler
> directive?
> 
>

-- 
Best regards,
David Stroupe
Keyed-Up Software
5307 Faireast Court
Arlington, Texas 76018-1683
817/557-4903 voice
817/472-0408 fax



^ permalink raw reply	[flat|nested] 10+ messages in thread
* Re: Array Initialization warnings
@ 2002-04-21  0:52 Oliver Kullmann
  0 siblings, 0 replies; 10+ messages in thread
From: Oliver Kullmann @ 2002-04-21  0:52 UTC (permalink / raw)
  To: gcc-help

> Hi David,
>
> > Just to clarify...the standard requires the brackets be placed as in
> > your example? If so, guess I had best get to bracketing my arrays.
> >
> It is pretty much up to you, how you handle your arrays. You can
> certainly use multi dimentional arrays and initialise them as such,
> or you could use one dimentional arrays and initialise them as such.
> There is nothing wrong with interpreting an x dimentional array as an
> y dimentional array, i am just saying, that you ought to be consistent.
> Your original code depended on a particular physical layout of the
> array. I am not sure, that physical layout is required by the standard.
>
> >I really did not want to have to go back and recode my array that looks
> >like this:BYTE SUBIMG_NTSC[2][2][4][3][8] = {...
>
> You might want to wait with a rewrite, until someone makes
> a stronger statement about this;)
>
> Yours sincerely,

> bjorn

Hi,

I copied a paragraph from the standard (ISO/IEC 14882:1998(E)):

When initializing a multi-dimensional array, the initializers 
initialize the elements with the last (rightmost) index of the array 
varying the fastest (8.3.4). 

[Example: int x[2][2] = { 3, 1, 4, 2 };
initializes x[0][0] to 3, x[0][1] to 1, x[1][0] to 4, and x[1][1] to 2. 
On the other hand, 
float y[4][3] = { { 1 }, { 2 }, { 3 }, { 4 } }; 
initializes the first column of y (regarded as a two-dimensional array) and 
leaves the rest zero. ]

(paragraph 8.5.1)

Oliver

^ permalink raw reply	[flat|nested] 10+ messages in thread
* RE:  Array Initialization warnings
@ 2002-04-20  8:37 David Stroupe
  2002-04-20  9:33 ` bjorn rohde jensen
  0 siblings, 1 reply; 10+ messages in thread
From: David Stroupe @ 2002-04-20  8:37 UTC (permalink / raw)
  To: gcc-help

  Hi guys,

Michal Liptak wrote:
 >
 > I think the internal representation of int[4][4] is the same as int[16]
 > m.
 >

That is usually the case, i would think, but i am not sure, it
is required by the standard, so i would not rely on that.

Just to clarify...the standard requires the brackets be placed as in 
your example? If so, guess I had best get to bracketing my arrays.

I really did not want to have to go back and recode my array that looks 
like this:
BYTE SUBIMG_NTSC[2][2][4][3][8] = {...

Thanks to all for the info!!



^ permalink raw reply	[flat|nested] 10+ messages in thread
* Array Initialization warnings
@ 2002-04-20  6:30 David Stroupe
  2002-04-20  6:56 ` bjorn rohde jensen
  0 siblings, 1 reply; 10+ messages in thread
From: David Stroupe @ 2002-04-20  6:30 UTC (permalink / raw)
  To: gcc-help

When I compile this line of code

int JPEG_MRK_NTSC[4][4] =
{
0x01, 0x02, 0x03, 0x04,
0x05, 0x06, 0x07, 0x08,
0x09, 0x0a, 0x0b, 0x0c,
0x0d, 0x0e, 0x0f, 0x00
};

 with the -Wall option, I get the following warnings

vis.c:264: warning: missing braces around initializer
vis.c:264: warning: (near initialization for `JPEG_MRK_NTSC[0]')

If I look at the values of the array members during execution, they are 
correct.

Is this array really being initialized correctly?
Are the warnings correct?

Is there a way to 'turn off' these particular warnings with a compiler 
directive?

TIA

-- 
Best regards,
David Stroupe
Keyed-Up Software


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2002-04-24 18:54 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-04-20  6:58 Array Initialization warnings David Stroupe
2002-04-20  7:06 ` Michal Liptak
2002-04-20  7:53   ` bjorn rohde jensen
2002-04-24 11:09     ` Sebastian Huber
2002-04-24 12:09       ` bjorn rohde jensen
  -- strict thread matches above, loose matches on Subject: below --
2002-04-21  0:52 Oliver Kullmann
2002-04-20  8:37 David Stroupe
2002-04-20  9:33 ` bjorn rohde jensen
2002-04-20  6:30 David Stroupe
2002-04-20  6:56 ` bjorn rohde jensen

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).