[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: structs and STL stack
From: |
Thomas Maeder |
Subject: |
Re: structs and STL stack |
Date: |
Sat, 18 Mar 2006 07:23:23 +0100 |
User-agent: |
Gnus/5.1006 (Gnus v5.10.6) XEmacs/21.4 (Jumbo Shrimp, linux) |
Christian Christmann <plfriko@yahoo.de> writes:
>>> This:
>>>
>>>> struct storeInfo {
>>>> int a;
>>>> } structInfo;
>>>
>>> defines both a type storeInfo and an object structInfo of that
>>> type. He suggests that you first define the type and then the
>>> object, in separate statements.
>
> Are there any disadvantages/potential problems when defining the
> struct type and directly initialize it in the same statement as can
> be seen above?
All other things being equal, I wouldn't know of any technical
disadvantage. Separating the two is certainly the more common way;
doing so may lead to code that the potential reader may be more
comfortable with.
In particular, in C it is quite common to see something like
typedef struct storeInfoTag {
int a;
} storeInfo;
. In C, storeInfoTag is not the name of a type, but can only be used
in connection with struct to name a type, e.g.:
struct storeInfoTag structInfo;
A novice reader might thus think that structInfo as defined in the
quote at the top of this post is a type, not an object.
That said, novice readers think many things (and so do not-so-novice
readers), and we can't protect ourselves against all of the wrong
things they may think.