Christian Christmann <[EMAIL PROTECTED]> 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.
_______________________________________________
help-gplusplus mailing list
help-gplusplus@gnu.org
http://lists.gnu.org/mailman/listinfo/help-gplusplus

Reply via email to