Subject: Re: rpcgen fix for -fshort-enums
To: <>
From: David Laight <>
List: tech-toolchain
Date: 02/05/2002 15:50:47
Todd Vierling wrote:

> : +     f_print(fout, "\t__rpcgen_%s_min = -0x7fffffff-1,\n", name);
> : +     f_print(fout, "\t__rpcgen_%s_max = 0x7fffffff,\n", name);

> I'm not sure how good these would be as far as portability (and
> readability!) is concerned.  I'd prefer to see:
>  f_print(fout, "\t__rpcgen_%s_max = (enum_t)0x7fffffff, /* int32_t */\n", name);
>  f_print(fout, "\t__rpcgen_%s_min = (-__rpcgen_%s_max)-1,\n", name, name);
> This way you're always qualifying it to the type to which you
> expect a cast.

Not really! the size of the enum depends on the value of the constant,
not its type.  So 'enum { x = (uint32_t)0 };' is still a byte.  Thus the
suggested cast only affects things if it truncates the value.  Given
(for XDR) we know we want 32 bit numbers - rather than anything else -
it is OTT.

If you are trying to define an enum with the same size as an arbitrary
typed integer then you have more fun (esp. if you want to avoid gcc
'enhancements' to C).  Try ((uintmax_t)~(int_type)0) >> 1)...