Re: cast unsigned long to long
- From: Jordan Abel <jmabel@xxxxxxxxxx>
- Date: 27 Dec 2005 16:56:19 GMT
On 2005-12-27, Keith Thompson <kst-u@xxxxxxx> wrote:
> "jeff" <xiayu02@xxxxxxxxx> writes:
>> unsigned long a = ...;
>> long b = (long)a;
>>
>> while a overflows, what is the result of b?
>
> The cast is unnecessary; the declaration
> long b = a;
> is equivalent, since there's an implicit conversion. (Most casts are
> unnecessary.)
>
> If a conversion to a signed integer type overflows, "either the result
> is implementation-defined or an implementation-defined signal is
> raised" (C99 6.3.1.3p3). I think the permission to raise a signal is
> new in C99; in C90, you just get an implementation-defined result.
> (No, it's not undefined.)
That's not considered "integer overflow"?
An example of undefined behavior is the behavior on integer overflow.
my mistake, it's not
>
> "Implementation-defined" means that your implementation is required to
> document it, but you shouldn't depend on this since it's likely to
> vary from one implementation to another, making your code
> non-portable.
>
> Note that this is different from what happens on artithmetic overflow,
> which invokes undefined behavior for signed types.
>
.
- References:
- cast unsigned long to long
- From: jeff
- Re: cast unsigned long to long
- From: Keith Thompson
- cast unsigned long to long
- Prev by Date: Re: cast unsigned long to long
- Next by Date: newbie fscanf %[ conversions, multipliers
- Previous by thread: Re: cast unsigned long to long
- Next by thread: Re: cast unsigned long to long
- Index(es):
Relevant Pages
|