Hi to all recently i noticed a strange behavior debugging a a simple code that i wrote in C for the Mitsubishi-Renesas microcontroller M16C: void Function_multiply(void) { unsigned char term1,term2,result; term1=6; term2=8; result= term1 * term2; } I expect that result=48 ,with no loss of data,being the 2 terms small numbers instead i have result=6 ,same with other small numers To have result=48 i need to declare the local variable as unsigned int. I dont think that i s a real bug,but i find strange that some option in the compiler could generate this unexpecyed situation Thanks you for your attention Have a nice weekend Diego,Milan Italy
Multiplication bug on EDE Crossview for M16C?
Started by ●February 9, 2008
Reply by ●February 9, 20082008-02-09
blisca wrote:> recently i noticed a strange behavior debugging a a simple code that i wrote > in C for the Mitsubishi-Renesas microcontroller M16C: > > void Function_multiply(void) > { > unsigned char term1,term2,result; > term1=6; > term2=8; > > result= term1 * term2; > } > I expect that result=48 ,with no loss of data,being the 2 terms small > numbers > > instead i have result=6 ,same with other small numers > > To have result=48 i need to declare the local variable as unsigned int. > > I dont think that i s a real bug,but i find strange that some option in the > compiler could generate this unexpecyed situationIf this is the exact code that you were using, how did you verify the result ? As stated, the function has no side effects, and the result value is ignored, so the compiler is free to optimize (part of) the function body away. If you use a debugger to look at the result, your results may not be reliable.
Reply by ●February 9, 20082008-02-09
On Sat, 09 Feb 2008 08:44:33 -0000, Arlet Ottens <usenet+5@c-scape.nl> = wrote:> blisca wrote: > >> recently i noticed a strange behavior debugging a a simple code that =i =>> wrote >> in C for the Mitsubishi-Renesas microcontroller M16C: >> void Function_multiply(void) >> { >> unsigned char term1,term2,result; >> term1=3D6; >> term2=3D8; >> result=3D term1 * term2; >> } >> I expect that result=3D48 ,with no loss of data,being the 2 terms sma=ll>> numbers >> instead i have result=3D6 ,same with other small numers >> To have result=3D48 i need to declare the local variable as unsigned=int.>> I dont think that i s a real bug,but i find strange that some option==>> in the >> compiler could generate this unexpecyed situation > > If this is the exact code that you were using, how did you verify the ==> result ? > As stated, the function has no side effects, and the result value is => ignored, so the compiler is free to optimize (part of) the function bo=dy => away. If you use a debugger to look at the result, your results may no=t => be reliable. >It would be very helpful to see what assembly is produced, if the assemb= ly is correct then the compiler is fine and its probably a debugger fault. = = Interesting tho.
Reply by ●February 9, 20082008-02-09
"Arlet Ottens" <usenet+5@c-scape.nl> ha scritto nel messaggio news:47ad67f2$0$85785$e4fe514c@news.xs4all.nl...> blisca wrote: > > > recently i noticed a strange behavior debugging a a simple code that iwrote> > in C for the Mitsubishi-Renesas microcontroller M16C: > > > > void Function_multiply(void) > > { > > unsigned char term1,term2,result; > > term1=6; > > term2=8; > > > > result= term1 * term2; > > } > > I expect that result=48 ,with no loss of data,being the 2 terms small > > numbers > > > > instead i have result=6 ,same with other small numers > > > > To have result=48 i need to declare the local variable as unsigned int. > > > > I dont think that i s a real bug,but i find strange that some option inthe> > compiler could generate this unexpecyed situation > > If this is the exact code that you were using, how did you verify the > result ? > > As stated, the function has no side effects, and the result value is > ignored, so the compiler is free to optimize (part of) the function body > away. If you use a debugger to look at the result, your results may not > be reliable. >thanks for helping me No,this is not the exact code,in fact i use the result and it leads me to a bigger error let me know your hints Diego
Reply by ●February 9, 20082008-02-09
"Dave" <dave@dave.com> ha scritto nel messaggio news:op.t585lgzy22usyq@edl_laptop1.belkin... On Sat, 09 Feb 2008 08:44:33 -0000, Arlet Ottens <usenet+5@c-scape.nl> wrote:> blisca wrote: > >> recently i noticed a strange behavior debugging a a simple code that i >> wrote >> in C for the Mitsubishi-Renesas microcontroller M16C: >> void Function_multiply(void) >> { >> unsigned char term1,term2,result; >> term1=6; >> term2=8; >> result= term1 * term2; >> } >> I expect that result=48 ,with no loss of data,being the 2 terms small >> numbers >> instead i have result=6 ,same with other small numers >> To have result=48 i need to declare the local variable as unsigned int. >> I dont think that i s a real bug,but i find strange that some option >> in the >> compiler could generate this unexpecyed situation > > If this is the exact code that you were using, how did you verify the > result ? > As stated, the function has no side effects, and the result value is > ignored, so the compiler is free to optimize (part of) the function body > away. If you use a debugger to look at the result, your results may not > be reliable. >It would be very helpful to see what assembly is produced, if the assembly is correct then the compiler is fine and its probably a debugger fault. Interesting tho. ok,but i have it at work so i have to wait til next week to copy the section relative to the problem many thanks to you have you all a nice weekend