Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

0x80000000 as long

0 views
Skip to first unread message

kgold

unread,
May 25, 2002, 2:15:17 PM5/25/02
to
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


--
--
Ken Goldman kg...@watson.ibm.com 914-784-7646
--
comp.lang.c.moderated - moderation address: cl...@plethora.net

Jeffrey Turner

unread,
May 26, 2002, 2:22:20 PM5/26/02
to
kgold wrote:

> 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

those who know me have no need of my name

unread,
May 26, 2002, 2:22:17 PM5/26/02
to
<clcm-2002...@plethora.net> divulged:

>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

John Doe

unread,
May 26, 2002, 2:22:27 PM5/26/02
to
> #define ERR_CODE 0x80000000
> long rc = ERR_CODE;
>
<snipped>

> 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

Dan Pop

unread,
May 27, 2002, 7:11:24 PM5/27/02
to
In <clcm-2002...@plethora.net> those who know me have no need of my name <not-a-rea...@usa.net> writes:

><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

0 new messages