This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: C/C++ Bug (shifting chars.)


CC: egcs-bugs@cygnus.com


Sergei,

egcs and gcc are giving the correct results 7f and ffffffff

The calculation of c1 and c2 are NOT equivalent.

The calculation of c1 is evaluated as

char c1 = (char)((((int)c) << 3) >> 3);

The calculation of c2 is evaluated as

char c2 = (char)(((int)((char)(((int)c) << 3))) >> 3)

The difference is the truncation of the intermediate
result and subsequent sign extension.

Graham
            




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]