structs, wie schreiben?
-
Hi,
wie soll man am besten structs definieren und warum? Welchen Vorteil hat welche Variante?
Variante 1:
struct A { // [...] };
Variante 2:
typedef struct B { // [...] } B1, B2;
Variante 3:
typedef struct { // [...] } C;
Gruß,
euer Areuxer
-
Variante 1: ok, damit hast du dein
struct A
Variante 2: falsche Syntax
Variante 3: ebenfalls ok, du hast ein namensloses struct und mit typedef erzeugst du ein Datentype, der darauf basiert.Ob Variante 1 oder 3? Up to you, Geschmackssache.
-
in der msdn steht follgendes:
struct
This statement defines a C-style structure.Syntax
typedef [attributes]
struct [tag] {
memberlist
} structname;Syntax Elements
attributes
The attributes helpstring, helpcontext, uuid, hidden, and version are accepted before a struct statement. The attributes helpstring, helpcontext, and string are accepted on a structure member. For more information about the attributes accepted before a structure definition, see "Attribute Descriptions" earlier in this chapter. Attributes (including the brackets) can be omitted. If uuid is omitted, the structure is not specified uniquely in the system.
tag
An optional tag, as with a C struct.
memberlist
List of structure members defined with C syntax.
structname
Name by which the structure is known in the type library.
Comments