[comp.sys.mac.programmer] MPW C and C++

anders@penguin (Anders Wallgren) (02/18/90)

I figured I should follow up with a comment on how we fixed the
problem with C and C++ not agreeing on the size of enums.  The caveat
here is that not only do we need to share code between Pascal, C and
C++, but all of the C code that we have gets compiled on about 20
different platforms, including Unix, SunOS, VMS, DOS, MacOS, etc, so
we needed a fix that wouldn't inconvenience us too much.  As it is, we
ended up checking out and making changes to over 150 files in our
source tree, so I personally have lost a big chunk of patience with
Apple's compiler people.  Anyway, with that caveat, here's the
"workaround".

#ifdef MACS_COMPILER_PEOPLE_ARE_CLOWNS
#define ENUM_DEF(name) _ ## name; typedef short name
#else
#define ENUM_DEF(name) name
#endif

then,

typedef enum {
	PET_cat,
	PET_dog,
	PET_clown
} ENUM_DEF(PET);

becomes, on the mac:

typedef enum {
	/* stuff */
} _PET; typedef short PET;

and on all other platforms:

typedef enum {
	/* stuff */
} PET;

The advantage is that we can still use enums to populate the name
space, while we are assured that all compilers on the mac will agree
on the size of the data type that actually holds the enum value.

Anders