Re: Undesired automatic cast, workarounds?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Pablo,

> for some reason now the operator+ automatically converts the ubyte to int,

That's correct.  That's what the compiler should do.

> ... generating in the above code a warning.

What warnings are you enabling?  That should not be a default warning (but I
don't have GCC 4.3.1 at my disposal to confirm).

> This has been ok with all previous gcc compilers.

All previous GCC compilers promote unsigned char to int.  (I don't know of
any that promote unsigned char to unsigned int, but it could happen in some
uncommon kinds of architectures.)

> Is there any way to deactivate this?

There should be a -Wno-blah switch to turn off the warning.  But I'm
surprised that it is enabled in the first place.

The only way to deactivate promoting an unsigned char to int is to use a
different language which does not do that promotion.

Both C and C++ promote.

> I mean, not only the warning but avoiding the unnecesary casts?

To avoid the casts, use int or unsigned int instead of unsigned char.

HTH,
--Eljay


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux