Mail Archives: djgpp/1997/10/26/17:47:48
Brett Porter wrote:
> > bool scrn[640][480] = {0};
>
> Are you sure? I don't ever recall seeing this done.
This is correct. ANSI C dictates that remaining members are
automatically initialized with all-bits-zero. Note that this makes the
following code nonportable:
void *p[10] = { 0 };
p[0] is a null pointer, but the others are initialized with an
all-bits-zero address, which is not necessarily the null pointer.
> > bool foo[2][3] = { 0, 1, 0, 1, 0, 1};
>
> I'm almost certain this won't work, I think it should be
> {{0,1},{0,1},{0,1}}
No, this is legal as well. You can leave off higher level bracing.
> > bool foo[2][3] = {1};
> >
> > only sets the first item of the array to 1 but the rest to 0. As
> > for how
> > efficent (sp) this is, I don't know.
It is done at compile time, so inefficiency is irrelevant.
Writing
int a[4] = { 1 };
does _precisely the same thing as
int a[4] = { 1, 0, 0, 0 };
> > There could very well be some
> > un
> > desireable affects to this (which I would love to know myself) but
> > it
> > works.
The only disadvantage with it is that you can't use it to initialize
pointers to null pointers in the same way, since ANSI C does not
guarantee that the all-bits-zero address is the null pointer.
> This is not really a standard as mar as I know.
It's actually perfectly standard.
> What is wrong with
> just
> memset(foo, 0, sizeof(foo)); ?
It does precisely the same thing, but it is done at runtime, rather than
at compile time.
--
Erik Max Francis, &tSftDotIotE / mailto:max AT alcyone DOT com
Alcyone Systems / http://www.alcyone.com/max/
San Jose, California, United States / icbm://+37.20.07/-121.53.38
\
"After each war there is a little / less democracy to save."
/ Brooks Atkinson
- Raw text -