Re: Structure initialization
- From: pete <pfiland@xxxxxxxxxxxxxx>
- Date: Tue, 10 Jun 2008 15:24:16 -0400
Walter Roberson wrote:
In article <13f6f4be-d45e-48e6-a203-4aa8f66b9ccc@xxxxxxxxxxxxxxxxxxxxxxxxxxx>,
<jb.simon@xxxxxxxx> wrote:
Recently I was pinged in a code review about my use of the
initialization method
AStruct myStruct = { 0 } ;
Which initializes all elements of the myStruct to 0.
I was questioned on it because no one had seen this construct.
It does what you expected, and is, I believe, recognized by
experienced C programmers.
On the other hand, code reviews are often useful to catch constructs
that might be unclear to the student programmer who is going to
be asked to work on the code several years from now.
In my opinion, the code is correct and there is no value in changing
the code to explicitly initialize all the values "just in case" someone
doesn't understand the code; the explicit initialization would just
become a source of potential errors. But for future code maintenance,
it wouldn't hurt to put in a comment indicating that the entire
structure was being initialized; the comment code include a reference
to the specific section of the Standard for those who might be
a little too convinced that the code is mistaken.
If the only reason that a programmer
can't understand a particular C code construct,
is because the programmer doesn't know enough C,
then it's time to learn more C.
What kind of a programmer needs to be told that?
Are child labor laws no longer being enforced?
--
pete
.
- Follow-Ups:
- Re: Structure initialization
- From: Walter Roberson
- Re: Structure initialization
- From: santosh
- Re: Structure initialization
- References:
- Structure initialization
- From: jb . simon
- Re: Structure initialization
- From: Walter Roberson
- Structure initialization
- Prev by Date: Re: range for int
- Next by Date: Re: Stupid or clever hack?
- Previous by thread: Re: Structure initialization
- Next by thread: Re: Structure initialization
- Index(es):
Relevant Pages
|