Subject: Re: rpcgen fix for -fshort-enums
To: David Laight <david@l8s.co.uk>
From: Todd Vierling <tv@wasabisystems.com>
List: tech-toolchain
Date: 02/05/2002 11:26:26
On Tue, 5 Feb 2002, David Laight wrote:
: > 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.
The cast to enum_t above is rather more for readability, not code
correctness. Just putting 0x7fffffff in there is a bit vague. (Hence the
comment, too.)
: 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)...
It has to be *exactly* the size of an enum_t, no more and no less, as
interpreted by rpc/types.h. This is because rpcgen casts "enum foo *" to
"enum_t *".
--
-- Todd Vierling <tv@wasabisystems.com> * Wasabi & NetBSD: Run with it.
-- CDs, Integration, Embedding, Support -- http://www.wasabisystems.com/