Structures, Unions, and Enumerations

2. Structures, Unions, and Enumerations

2.1What's the difference betweenstruct x1 { ... }; and typedef struct { ... } x2; ?

2.2Why doesn't"struct x { ... }; x thestruct;" work?

2.3Can a structure contain a pointerto itself?

2.4What's the best way of implementing opaque (abstract) data types in C?

2.6I came across some code that declared a structurewith the last member an array of one element,and then did some tricky allocation to makeit act like the arrayhad several elements.Isthislegal or portable?

2.7I heardthat structures could be assignedto variables and passed to and from functions, but K&R1saysnot.

2.8Why can't you compare structures?

2.9Howarestructure passing and returningimplemented?

2.10CanI pass constant values to functions which accept structure arguments?

2.11How can I read/write structures from/todata files?

2.12How canI turn offstructurepadding?

2.13Why does sizeof report a larger size than I expect for a structure type?

2.14How can I determine the byte offset of a field within a structure?

2.15How can I access structure fields by name at run time?

2.18I have a program whichworks correctly, butdumps coreafter itfinishes.Why?

2.20Can I initialize unions?

2.22What is the difference betweenan enumeration and a set ofpreprocessor #defines?

2.24Is there an easy way to print enumeration values symbolically?


top