Peter Doerfler wrote:
Never mind this approach. Now sizeof(foo) is 12 instead of 4 as it was before, which is probably not acceptable for most applications. I guess it's either compile without strict compliance or use the __extension__ workaround and make sure all the compilers you want to use on your code know what to do. Such a thing as an anonymous struct simply doesn't seem to exist in the Standard.
The following seems to work with -Wextra -pedantic, although it uses accessors, which require a lot of changes to the code that uses Coords:
typedef signed short Sint16; typedef unsigned int Uint32; struct Coords { Coords(const int X, const int Y) {parts.x = X, parts.y = Y;} bool operator<(const Coords other) const {return all < other.all;} signed short int get_x() const {return parts.x;} signed short int get_y() const {return parts.y;} void set_x(const Sint16 X) {parts.x = X;} void set_y(const Sint16 Y) {parts.y = Y;} union { struct {Sint16 x, y;} parts; Uint32 all; }; };