RE: Strange shifting behaviour

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

 



Eljay,

Though I agree with your point about the standards and
undefined behavior, I do believe that Ulf has identified
a quality of implementation issue.

Would you not agree that compile-time expression evaluation
should mimic run-time as much as possible?  Or to put it
another way, the more often compile-time and run-time
evaluated results diverge, the lower the subject quality
of the compiler.

If the shift operator at run-time examines only the lower
order 5 bits of the shift count (as Ulf's x86 does) then
a "high-quality" compile-time expression evaluator ought
to do the same.

/john

-----Original Message-----
From: Eljay Love-Jensen [mailto:eljay@xxxxxxxxx]
Sent: Tuesday, July 12, 2005 6:46 PM
To: Ulf Magnusson; gcc-help@xxxxxxxxxxx
Subject: Re: Strange shifting behaviour


Hi Ulf,

>When shifting an int by its size in bits...

That is undefined behavior (implementation dependent), as per C and C++ standards.  Ever since C was first taking it's first baby steps.

By "undefined behavior", that means any given particular implementation can:
+ not do anything
+ do what you expect
+ SEGV
+ format your hard drive

--Eljay



[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