On 22/04/13 19:32, Paul Sokolovsky wrote: > Hello, > > On Mon, 22 Apr 2013 17:39:27 +0200 > David Brown <da...@westcontrol.com> wrote: > >> Hi, >> >> When I compile the code you gave below (using gcc 4.6.3 from >> 20120406), I get: >> >> warning: left shift count >= width of type [enabled by default] >> >> That is even without any sort of warning flags - and you should >> normally enable lots of warnings. >> >> So here you have undefined code, and the compiler tells you of the >> problem. You really cannot get better than that by trying to invent >> your own ideas about how you want to define this undefined behaviour. > > Yeah, but can get better by leveraging generally accepted ideas (math > def of shift) and ideas put by more than just "you" into similar cases > (other well known gcc ports, like x86) ;-). >
Defining (x << n) = (x * 2^(n % 16)) & 0xffff is just as good a mathematical definition as your desired (x << n) = (x * 2^n) & 0xffff (for 16-bit ints) Neither definition is "normal" mathematics. And note that gcc on the x86 has exactly the same effect - it's just that with 32-bit ints, you get it with shifts of 32-bits or more. > Thanks for all the flame, guys! ;-). > You're welcome :-) It's important to think about these things and get the correct. ------------------------------------------------------------------------------ Precog is a next-generation analytics platform capable of advanced analytics on semi-structured data. The platform includes APIs for building apps and a phenomenal toolset for data science. Developers can use our toolset for easy data analysis & visualization. Get a free account! http://www2.precog.com/precogplatform/slashdotnewsletter _______________________________________________ Mspgcc-users mailing list Mspgcc-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mspgcc-users