From: Jan W. <we...@ef...> - 2010-07-29 09:08:32
|
I tried #include <stdio.h> #include <assert.h> int main(void) { volatile unsigned short vus = 0xfffe; printf("sizeof(int)=%d, sizeof(short)=%d, sizeof(long long)=%d\n", sizeof(int), sizeof(short), sizeof(long long)); printf("%lld\n", (long long)(vus * vus)); assert (vus * vus >= 1); assert (vus * vus <= 1); assert (vus * vus == 1); } in cygwin & gcc 4.3.4 with -O2: sizeof(int)=4, sizeof(short)=2, sizeof(long long)=8 -262140 assertion "vus * vus == 1" failed: file "n.c", line 10, function: main Aborted (core dumped) Funny, but as I said, not unreasonable. JW ----- Original Message --------------- Subject: Re: [sdcc-devel] gcc integer promotion From: Jan Waclawek <we...@ef...> Date: Thu, 29 Jul 2010 10:08:34 +0200 To: Development chatter about sdcc <sdc...@li...> >I believe the less-optimised version simply performs the multiplication in hardware and then interprets the result as signed int. The optimiser has more space to "think", thus "knows" that the result is undefined and uses thus some suitable constant (zero?). > >I would like to see uint64_t(vus * vus) printf'd (along with sizeof(int) and sizeof(short)) in the different cases. > >JW > > > >----- Original Message --------------- >>Jan, >> >>thank you for the explanation. The strange thing is (but you explained >>it is valid) that the same compiler behaves differently depending on >>optimization options. >> >> >>This means that the regtest >> >>volatile unsigned short vus = 0xfffe; >>assert (vus * vus< 1); >> >> >>is implementation dependent, so it should be removed. >> >>Borut >> > > >------------------------------------------------------------------------------ >The Palm PDK Hot Apps Program offers developers who use the >Plug-In Development Kit to bring their C/C++ apps to Palm for a share >of $1 Million in cash or HP Products. Visit us here for more details: >http://p.sf.net/sfu/dev2dev-palm >_______________________________________________ >sdcc-devel mailing list >sdc...@li... >https://lists.sourceforge.net/lists/listinfo/sdcc-devel |