libunwind-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Libunwind-devel] [patch] Remove unnecessary calls to labs()


From: Dmitri Shubin
Subject: Re: [Libunwind-devel] [patch] Remove unnecessary calls to labs()
Date: Wed, 29 Oct 2014 10:58:40 +0400

Hi,

On Wed, Oct 22, 2014 at 10:23 PM, Paul Pluzhnikov <address@hidden> wrote:
For the curious:

  unsigned long u1 = ~0UL;
  unsigned long u2 = labs(u1);

  assert(u1 != u2);  // labs on unsigned *may* have an effect, despite
what Clang says.

Am I right that this is 'implementation-defined' behaviour?
According to C99:

6.3.1.3 Signed and unsigned integers
1 When a value with integer type is converted to another integer type other than _Bool, if
 the value can be represented by the new type, it is unchanged.
2 Otherwise, if the new type is unsigned, the value is converted by repeatedly adding or
 subtracting one more than the maximum value that can be represented in the new type
until the value is in the range of the new type.49)
3 Otherwise, the new type is signed and the value cannot be represented in it; either the
 result is implementation-defined or an implementation-defined signal is raised.

So here we have p3.

Regards.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]