Undesired automatic cast, workarounds?

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

 



Hello all,

I tried yesterday GCC 4.3.1 for the first time, and I encountered a bad 
surprise.  If I do

typedef unsigned char ubyte;
ubyte a,b,c;
c=a+b;
c+=a;

for some reason now the operator+ automatically converts the ubyte to int, 
generating in the above code a warning.  This has been ok with all previous 
gcc compilers.  Is there any way to deactivate this?  I mean, not only the 
warning but avoiding the unnecesary casts?  This new behaviour is even worse 
in the following cases:

typedef signed char byte;
byte a,b,c;
...
a=-b;  // the operator- also produces an int !

or 

c=b/a; // the operator/ also produces an int

in the later cases the casts to are absolutelly innecessary, since the results 
are always in range (assuming a!=0 of course)!

Any hints will be very welcome,

Pablo

[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