Re: Array initalization doubt.

From: dandelion (dandelion_at_meadow.net)
Date: 10/26/04


Date: Tue, 26 Oct 2004 17:05:57 +0200


"Jack Klein" <jackklein@spamcop.net> wrote in message
news:kadrn0pcg3epoovo5lpgff90um26p0hdk6@4ax.com...
> On Mon, 25 Oct 2004 14:43:21 +0200, "dandelion" <dandelion@meadow.net>
> wrote in comp.lang.c:
>
> >
> > "K.M. Jr." <km_jr_usenet@yahoo.com> wrote in message
> > news:7f8bb583.0410250237.7ddc4f7f@posting.google.com...
> > > Hi all,
> > >
> > > Consider this line -
> > >
> > > char s[30] = "\0";
> > >
> > > Does this initialize all array elements to zero ?
> >
> > The standards guys will answer that definitively. My guess is a
resounding
> > "no" in the sense that I would not count on it. I think only s[0] gets
> > initialized.
>
> You don't have to count on it, but the answer is most definitely
> 'yes'.

I noticed.

I still don't count on it for two reasons:

a) If I initialize a structure, I initialize it fully for the sake of
clarity of code.

b) I've had one expirience too much of compiler which *almost* but *not*
quite implement the
    entire standard. "Oops... Shit... Sorry. There's a section in the manual
about it on page 652! You
    should have read that."

Neither of these reasons is a critique of either the standard, nor the guys
(and that includes you) explaining it, but merely reflects my style of
programming in which clarity of code plays a much more important role than
saving a few characters (or even lines) of code.



Relevant Pages

  • Re: Numeric Edited and VALUE/MOVE
    ... Initialize Num-Edi to Value ... then all would work "as defined in the Standard". ... MYFLD PIC ZZZ,Z VALUE ALL '9'. ... What happens when you INITIALIZE MYFLD TO VALUE? ...
    (comp.lang.cobol)
  • Re: [C++] Need help with program please
    ... a return statement can involve the construction and copy of a ... That's what the function return mechanism does -- initialize the ... The standard clearly specifies that returning an rvalue ... >>perspective, objects have addresses, but temporaries don't. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: "a < b < c" not the same as "(a < b) && (b < c)"?
    ... >> One question is what are automatic variables in a function (not ... I'm going to take that as including pointers. ... initialize anything I use, so I never really think about it. ... > Have you considered getting a copy of the standard? ...
    (comp.lang.c)
  • Re: Reset data
    ... Move Table1 to Tabl ... In the '85 Standard it was ... "non-conforming" to try to INITIALIZE a record that included an OCCURS ... SOME vendors provided extensions to allow this, ...
    (comp.lang.cobol)
  • Re: Cohens paper on byte order
    ... Nothing in the whole standard appears to me to try to talk ... > are external to the FIPS but which are used to test the validity of AES ... valid although obscure reasons, ...
    (sci.crypt)