Coding: Data Structures

The declaration of structure members should follow the same guidelines as those for variables. The major differences are that it may sometimes be very convenient to have certain members close together (for movement or storage efficiency), and it may occasionally be necessary to have part of one struct match part of another struct. Both of these can violate the alphabetical guideline. This conflict can be resolved by creating a new struct and making that a member. However, this is often unwieldy, so don't bother when it's not all that important. In the case of movement/storage efficiency, just go ahead and put them out of order, especially if the struct is small. Even then, though, it would be good to have them properly ordered within any such grouping. Since matching can be very important, do create a new struct in that case, and put it as a member in all structs that must have a matching piece.

Use flags efficiently. Do not use anything larger than one byte for simple flags, and if there are multiple closely related flags and you are getting tight on memory, combine them into a bitfield.