#define ERR_CODE 0x80000000
long rc = ERR_CODE;
I just hit a compiler that complains
converting 214781.... to type long int does not preserve its value.
Sure enough, my H&S says that 0x80000000 is conventionally long int
but is unsigned long in ISO C.
Is there a fix other than
#define ERR_CODE (long)0x80000000
--
--
Ken Goldman kg...@watson.ibm.com 914-784-7646
--
comp.lang.c.moderated - moderation address: cl...@plethora.net
> After years of creating error codes like:
>
> #define ERR_CODE 0x80000000
> long rc = ERR_CODE;
>
> I just hit a compiler that complains
>
> converting 214781.... to type long int does not preserve its value.
>
> Sure enough, my H&S says that 0x80000000 is conventionally long int
> but is unsigned long in ISO C.
>
> Is there a fix other than
>
> #define ERR_CODE (long)0x80000000
#define ERR_CODE LONG_MIN
Just a guess.
--Jeffrey Turner
Senior Engineer
No-wei Firmware
Leaders in firmware design and debugging for over a fortnight
>Sure enough, my H&S says that 0x80000000 is conventionally long int
>but is unsigned long in ISO C.
>
>Is there a fix other than
>
> #define ERR_CODE (long)0x80000000
`L' suffix?
#define ERR_CODE 0x80000000L
--
bringing you boring signatures for 17 years
> Is there a fix other than
>
> #define ERR_CODE (long)0x80000000
#define ERR_CODE 0x80000000L
--
Martijn
If at first you don't succeed, then skydiving isn't for you
><clcm-2002...@plethora.net> divulged:
>
>>Sure enough, my H&S says that 0x80000000 is conventionally long int
>>but is unsigned long in ISO C.
Only if it cannot be represented by the type long int.
In C89, the type of this constant is the first type that can represent it
in the following list: int, unsigned int, long int, unsigned long int.
In C99, the list is longer, but this is irrelevant, since 0x80000000 is
guaranteed to be representable by the unsigned long type.
>>Is there a fix other than
>>
>> #define ERR_CODE (long)0x80000000
>
>`L' suffix?
>
> #define ERR_CODE 0x80000000L
It doesn't help: if the *value* 0x80000000 cannot be represented by the
type long, the type of the constant will be unsigned long.
Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Dan...@ifh.de