2 ms·
Funny, I used a union once to port code when I found-out zero sized arrays were a gcc thing: /* * SC C Compiler 8.8.4f1 (part of MPW 3.3) does not support
by mzs 11y ago
Funny, I used a union once to port code when I found-out zero sized arrays were a gcc thing:
/*
* SC C Compiler 8.8.4f1 (part of MPW 3.3) does not support zero sized
* arrays. I use this 'clever' trick involving the preprocessor that
* guarantees everything is aligned appropriately. It is possible with
* this that some space will be wasted between the header and the
* payload if the a single element of the payload is larger than the
* header, but that is not the case here.
*/
#if 0
struct state {
mbhdr_t st_mb; /* Screen 1, Line 1 */
short st_serln; /* Screen 1, Line 2 */
short st_astln;
unsigned char st_count;
unsigned char st_unit;
char st_qs[2];
char st_units; /* Screen 1, Line 3 */
avunit_t st_avms[0];
};
#else
struct state {
union {
struct {
mbhdr_t suh_mb; /* Screen 1, Line 1 */
short suh_serln; /* Screen 1, Line 2 */
short suh_astln;
unsigned char suh_count;
unsigned char suh_unit;
char suh_qs[2];
char suh_units; /* Screen 1, Line 3 */
} su_header;
avunit_t su_align[1];
} st_union[1];
};
#define st_mb st_union[0].su_header.suh_mb
#define st_serln st_union[0].su_header.suh_serln
#define st_astln st_union[0].su_header.suh_astln
#define st_count st_union[0].su_header.suh_count
#define st_unit st_union[0].su_header.suh_unit
#define st_qs st_union[0].su_header.suh_qs
#define st_units st_union[0].su_header.suh_units
#define st_avms st_union[1].su_align
#endif