Help with GCC, please
Sergei Organov
osv at topconrd.ru
Mon Aug 22 10:47:16 UTC 2005
leonp at plris.com writes:
> Hello, all.
>
> I ask for pardon, as the question is not on RTEMS proper, but on the
> rtems-GCC.
> May be somebody knows...:-(
>
> I wrote:
> unsigned char* cp;
> .....
> if (cp[6] == (cp[0]+cp[1]+cp[2]+cp[3]+cp[4]+cp[5]))
> ....
> The comparison never becomes equal, as the assembler code generates such
> commands that the result at the right side is unsigned long.
No, the result is unsigned int. You need:
if (cp[6] == (unsigned char)(cp[0]+cp[1]+cp[2]+cp[3]+cp[4]+cp[5]))
>
> Why?
Due to the C type promotion rules in expressions. Refer to C language
specs.
--
Sergei.
More information about the users
mailing list