Re: Optimisations and undefined behaviour

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

 



On 2015-11-08 21:02:58 +0100, Marc Glisse wrote:
> On Sun, 8 Nov 2015, Jeff Law wrote:
> 
> >On 11/08/2015 12:11 PM, Florian Weimer wrote:
> >>On 11/06/2015 01:32 PM, David Brown wrote:
> >>>How about this case:
> >>>
> >>>int foo(int x) {
> >>>	if (x > 1290) {
> >>>		printf("X is wrong here %d, but we don't care\n", x);
> >>>	}
> >>>	return x*x*x;
> 
> Why not simply:
>   unsigned y = x;
>   return y*y*y;
> ? This is an example where defined behavior is so easy to get...

But what if the result of y*y*y (an unsigned int) does not fit in
an int?

-- 
Vincent Lefèvre <vincent@xxxxxxxxxx> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux