[Bug 1822] Cast parameters of lm32_interrupt_* to uint32_t

bugzilla-daemon at rtems.org bugzilla-daemon at rtems.org
Mon Jul 11 12:40:04 UTC 2011


https://www.rtems.org/bugzilla/show_bug.cgi?id=1822

--- Comment #5 from Sebastian Huber <sebastian.huber at embedded-brains.de> 2011-07-11 07:40:04 CDT ---
(In reply to comment #4)
> Ah, indeed, you are right. I just tried the following program and it prints the
> same values for b and c:
> 
> int main()
> {
>     unsigned char a;
>     unsigned int b, c;
> 
>     a = 0xff;
>     b = ~a;
>     c = ~((unsigned int)a);
>     printf("%08x %08x\n", b, c);
>     return 0;
> }
> 
> I thought that the tilde operator applied to e.g. a char would yield another
> char that would only later be cast to integer; but apparently the tilde
> operator casts to integer before complementing.

No, please look in the C standard (keyword "usual integer conversion rules").

> Now you can either add an explicit cast to avoid ambiguities, or take the
> position that people should learn the various idiosyncrasies of the C language.

A clean way would be to use an inline function or an assignment to a local
variable.  I don't think that adding a cast is good here.  It may prevent a
warning.

-- 
Configure bugmail: https://www.rtems.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are watching all bug changes.



More information about the bugs mailing list