This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Optimisations and undefined behaviour


On Mon, Nov 09, 2015 at 01:27:34AM +0100, Vincent Lefevre wrote:
> > 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?

That is implementation-defined. not undefined (6.3.1.3); GCC documents
it like this:

     For conversion to a type of width N, the value is reduced modulo
     2^N to be within range of the type; no signal is raised.


Segher


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]