Possible issue with integer promotion for << and >> in gcc.4.5.3
Arthur Schwarz
aschwarz1309@att.net
Tue Dec 18 22:40:00 GMT 2012
Cygwin gcc 4.5.3
I have run some tests to determine the gcc 4.5.3 integer promotion policies. The
tests show that for 'char' input, "char << long" and "char >> long" promote to
INT while other operations using a long promote to" long", and that "char <<
ulong" and "char >> ulong" promote to INT while other operations using ulong
promote to "ulong". In similar fashion, "long << long" and "long >> long"
promote to INT while other promotions are to long, and that "long << ulong" and
"long >> ulong" promote to long while other operations promote to ulong. The
code used and the output are included below.
The code is not production code.
I think the code is correct and that my interpretation is also correct. I
realize that gcc 4.5.3 is no longer supported so if my guess is correct do I
have to switch to mingw (for precompiled later compilers)?
==================== output ====================
func0(char 1)
!x 0 0x00000000 BOOL
~x -2 0xfffffffe INT
+x 1 0x00000001 INT
-x -1 0xffffffff INT
++x 3 0x00000002 CHAR
--x -1 0x00000000 CHAR
x++ 2 0x00000001 CHAR
x-- 0 0x00000001 CHAR
func1(char -1, bool true)
x + y 0 0x00000000 INT
x - y -2 0xfffffffe INT
x * y -1 0xffffffff INT
x / y -1 0xffffffff INT
x % y 1 0x00000001 INT
x << y -2 0xfffffffe INT
x >> y -1 0xffffffff INT
x & y 1 0x00000001 INT
x | y -1 0xffffffff INT
x ^ x -2 0xfffffffe INT
func1(char -1, char 1)
x + y 0 0x00000000 INT
x - y -2 0xfffffffe INT
x * y -1 0xffffffff INT
x / y -1 0xffffffff INT
x % y 1 0x00000001 INT
x << y -2 0xfffffffe INT
x >> y -1 0xffffffff INT
x & y 1 0x00000001 INT
x | y -1 0xffffffff INT
x ^ x -2 0xfffffffe INT
func1(char -1, uchar 1)
x + y 0 0x00000000 INT
x - y -2 0xfffffffe INT
x * y -1 0xffffffff INT
x / y -1 0xffffffff INT
x % y 1 0x00000001 INT
x << y -2 0xfffffffe INT
x >> y -1 0xffffffff INT
x & y 1 0x00000001 INT
x | y -1 0xffffffff INT
x ^ x -2 0xfffffffe INT
func1(char -1, long 1)
x + y 0 0x00000000 LONG
x - y -2 0xfffffffe LONG
x * y -1 0xffffffff LONG
x / y -1 0xffffffff LONG
x % y 1 0x00000001 LONG
x << y -2 0xfffffffe INT
x >> y -1 0xffffffff INT
x & y 1 0x00000001 LONG
x | y -1 0xffffffff LONG
x ^ x -2 0xfffffffe LONG
func1(char -1, ulong 1)
x + y 0 0x00000000 ULONG
x - y 4294967294 0xfffffffe ULONG
x * y 4294967295 0xffffffff ULONG
x / y 4294967295 0xffffffff ULONG
x % y 1 0x00000001 ULONG
x << y -2 0xfffffffe INT
x >> y -1 0xffffffff INT
x & y 1 0x00000001 ULONG
x | y 4294967295 0xffffffff ULONG
x ^ x 4294967294 0xfffffffe ULONG
func0(long 1)
!x 0 0x00000000 BOOL
~x -2 0xfffffffe LONG
+x 1 0x00000001 LONG
-x -1 0xffffffff LONG
++x 3 0x00000003 LONG
--x -1 0xffffffff LONG
x++ 2 0x00000001 LONG
x-- 0 0x00000001 LONG
func1(long -1, bool true)
x + y 0 0x00000000 LONG
x - y -2 0xfffffffe LONG
x * y -1 0xffffffff LONG
x / y -1 0xffffffff LONG
x % y 1 0x00000001 LONG
x << y -2 0xfffffffe LONG
x >> y -1 0xffffffff LONG
x & y 1 0x00000001 LONG
x | y -1 0xffffffff LONG
x ^ x -2 0xfffffffe LONG
func1(long -1, char 1)
x + y 0 0x00000000 LONG
x - y -2 0xfffffffe LONG
x * y -1 0xffffffff LONG
x / y -1 0xffffffff LONG
x % y 1 0x00000001 LONG
x << y -2 0xfffffffe LONG
x >> y -1 0xffffffff LONG
x & y 1 0x00000001 LONG
x | y -1 0xffffffff LONG
x ^ x -2 0xfffffffe LONG
func1(long -1, uchar 1)
x + y 0 0x00000000 LONG
x - y -2 0xfffffffe LONG
x * y -1 0xffffffff LONG
x / y -1 0xffffffff LONG
x % y 1 0x00000001 LONG
x << y -2 0xfffffffe LONG
x >> y -1 0xffffffff LONG
x & y 1 0x00000001 LONG
x | y -1 0xffffffff LONG
x ^ x -2 0xfffffffe LONG
func1(long -1, long 1)
x + y 0 0x00000000 LONG
x - y -2 0xfffffffe LONG
x * y -1 0xffffffff LONG
x / y -1 0xffffffff LONG
x % y 1 0x00000001 LONG
x << y -2 0xfffffffe LONG
x >> y -1 0xffffffff LONG
x & y 1 0x00000001 LONG
x | y -1 0xffffffff LONG
x ^ x -2 0xfffffffe LONG
func1(long -1, ulong 1)
x + y 0 0x00000000 ULONG
x - y 4294967294 0xfffffffe ULONG
x * y 4294967295 0xffffffff ULONG
x / y 4294967295 0xffffffff ULONG
x % y 1 0x00000001 ULONG
x << y -2 0xfffffffe LONG
x >> y -1 0xffffffff LONG
x & y 1 0x00000001 ULONG
x | y 4294967295 0xffffffff ULONG
x ^ x 4294967294 0xfffffffe ULONG
===================== code ====================
# include <iostream>
# include <iomanip>
# include <typeinfo>
# include "cstdio"
# include <cstdlib>
using namespace std;
typedef unsigned char UCHAR;
typedef unsigned short USHORT;
typedef unsigned int INT;
typedef unsigned long ULONG;
string find(type_info* info) {
struct type {
type_info* typeInfo;
string name;
};
int i;
static type types[] = { {const_cast<type_info*>(&typeid(bool)), " BOOL" }
, {const_cast<type_info*>(&typeid(char)), " CHAR" }
, {const_cast<type_info*>(&typeid(UCHAR)), " UCHAR" }
, {const_cast<type_info*>(&typeid(short)), " SHORT" }
, {const_cast<type_info*>(&typeid(USHORT)), " USHORT"}
, {const_cast<type_info*>(&typeid(int)), " INT" }
, {const_cast<type_info*>(&typeid(uint)), " UINT" }
, {const_cast<type_info*>(&typeid(long)), " LONG" }
, {const_cast<type_info*>(&typeid(ULONG)), " ULONG" }
};
for(i = 0; i < sizeof(types)/sizeof(types[0]); i++ )
if (types[i].typeInfo == info) break;
if (i >= sizeof(types)/sizeof(types[0])) return " NOT FOUND";
return types[i].name;
}
void func0(char x) {
ios_base::fmtflags ioFlags = cout.flags();
string info = find(const_cast<type_info*>(&typeid(x)));
char save = x;
cout << "func0(char " << (long)x << ')' << endl;
cout << "!x " << setw(12) << (!x) << " 0x" << setw(8) << setfill('0') <<
hex << (!x) << find(const_cast<type_info*>(&typeid(!x))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "~x " << setw(12) << (~x) << " 0x" << setw(8) << setfill('0') <<
hex << (~x) << find(const_cast<type_info*>(&typeid(~x))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "+x " << setw(12) << (+x) << " 0x" << setw(8) << setfill('0') <<
hex << (+x) << find(const_cast<type_info*>(&typeid(+x))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "-x " << setw(12) << (-x) << " 0x" << setw(8) << setfill('0') <<
hex << (-x) << find(const_cast<type_info*>(&typeid(-x))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "++x " << setw(12) << (long)(++x) << " 0x" << setw(8) <<
setfill('0') << hex << (long)(++x) <<
find(const_cast<type_info*>(&typeid(++x))) << endl;
cout.flags(ioFlags); cout << setfill(' '); x = save;
cout << "--x " << setw(12) << (long)(--x) << " 0x" << setw(8) <<
setfill('0') << hex << (long)(--x) <<
find(const_cast<type_info*>(&typeid(--x))) << endl;
cout.flags(ioFlags); cout << setfill(' '); x = save;
cout << "x++ " << setw(12) << (long)(x++) << " 0x" << setw(8) <<
setfill('0') << hex << (long)(x++) <<
find(const_cast<type_info*>(&typeid(x++))) << endl;
cout.flags(ioFlags); cout << setfill(' '); x = save;
cout << "x-- " << setw(12) << (long)(x--) << " 0x" << setw(8) <<
setfill('0') << hex << (long)(x--) <<
find(const_cast<type_info*>(&typeid(x--))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << endl;
}
void func1(char x, char y) {
ios_base::fmtflags ioFlags = cout.flags();
cout << "func1(char " << (signed long)x << ", char " << (unsigned long)y <<
')' << endl;
cout << "x + y " << setw(12) << (x + y) << " 0x" << setw(8) << setfill('0')
<< hex << (x + y) << find(const_cast<type_info*>(&typeid(x + y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "x - y " << setw(12) << (x - y) << " 0x" << setw(8) << setfill('0')
<< hex << (x - y) << find(const_cast<type_info*>(&typeid(x - y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "x * y " << setw(12) << (x * y) << " 0x" << setw(8) << setfill('0')
<< hex << (x * y) << find(const_cast<type_info*>(&typeid(x * y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
if (y == 0) {
cout << "x / y " << x << " / 0" << endl;
} else {
cout << "x / y " << setw(12) << (x / y) << " 0x" << setw(8) <<
setfill('0') << hex << (x / y) << find(const_cast<type_info*>(&typeid(x / y)))
<< endl;
}
cout.flags(ioFlags); cout << setfill(' ');
cout << "x % y " << setw(12) << (x & y) << " 0x" << setw(8) << setfill('0')
<< hex << (x & y) << find(const_cast<type_info*>(&typeid(x & y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "x << y " << setw(12) << (x << y) << " 0x" << setw(8) << setfill('0')
<< hex << (x << y) << find(const_cast<type_info*>(&typeid(x << y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "x >> y " << setw(12) << (x >> y) << " 0x" << setw(8) << setfill('0')
<< hex << (x >> y) << find(const_cast<type_info*>(&typeid(x >> y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "x & y " << setw(12) << (x & y) << " 0x" << setw(8) << setfill('0')
<< hex << (x & y) << find(const_cast<type_info*>(&typeid(x & y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "x | y " << setw(12) << (x | y) << " 0x" << setw(8) << setfill('0')
<< hex << (x | y) << find(const_cast<type_info*>(&typeid(x | y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "x ^ x " << setw(12) << (x ^ y) << " 0x" << setw(8) << setfill('0')
<< hex << (x ^ y) << find(const_cast<type_info*>(&typeid(x ^ y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << endl;
}
void func1(char x, bool y) {
ios_base::fmtflags ioFlags = cout.flags();
cout << "func1(char " << (signed long)x << ", bool " << boolalpha << y << ')'
<< noboolalpha << endl;
cout << "x + y " << setw(12) << (x + y) << " 0x" << setw(8) << setfill('0')
<< hex << (x + y) << find(const_cast<type_info*>(&typeid(x + y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "x - y " << setw(12) << (x - y) << " 0x" << setw(8) << setfill('0')
<< hex << (x - y) << find(const_cast<type_info*>(&typeid(x - y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "x * y " << setw(12) << (x * y) << " 0x" << setw(8) << setfill('0')
<< hex << (x * y) << find(const_cast<type_info*>(&typeid(x * y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
if (y == 0) {
cout << "x / y " << x << " / 0" << endl;
} else {
cout << "x / y " << setw(12) << (x / y) << " 0x" << setw(8) <<
setfill('0') << hex << (x / y) << find(const_cast<type_info*>(&typeid(x / y)))
<< endl;
}
cout.flags(ioFlags); cout << setfill(' ');
cout << "x % y " << setw(12) << (x & y) << " 0x" << setw(8) << setfill('0')
<< hex << (x & y) << find(const_cast<type_info*>(&typeid(x & y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "x << y " << setw(12) << (x << y) << " 0x" << setw(8) << setfill('0')
<< hex << (x << y) << find(const_cast<type_info*>(&typeid(x << y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "x >> y " << setw(12) << (x >> y) << " 0x" << setw(8) << setfill('0')
<< hex << (x >> y) << find(const_cast<type_info*>(&typeid(x >> y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "x & y " << setw(12) << (x & y) << " 0x" << setw(8) << setfill('0')
<< hex << (x & y) << find(const_cast<type_info*>(&typeid(x & y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "x | y " << setw(12) << (x | y) << " 0x" << setw(8) << setfill('0')
<< hex << (x | y) << find(const_cast<type_info*>(&typeid(x | y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "x ^ x " << setw(12) << (x ^ y) << " 0x" << setw(8) << setfill('0')
<< hex << (x ^ y) << find(const_cast<type_info*>(&typeid(x ^ y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << endl;
}
void func1(char x, unsigned char y) {
ios_base::fmtflags ioFlags = cout.flags();
cout << "func1(char " << (signed long)x << ", uchar " << (unsigned long)y <<
')' << endl;
cout << "x + y " << setw(12) << (x + y) << " 0x" << setw(8) << setfill('0')
<< hex << (x + y) << find(const_cast<type_info*>(&typeid(x + y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "x - y " << setw(12) << (x - y) << " 0x" << setw(8) << setfill('0')
<< hex << (x - y) << find(const_cast<type_info*>(&typeid(x - y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "x * y " << setw(12) << (x * y) << " 0x" << setw(8) << setfill('0')
<< hex << (x * y) << find(const_cast<type_info*>(&typeid(x * y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
if (y == 0) {
cout << "x / y " << x << " / 0" << endl;
} else {
cout << "x / y " << setw(12) << (x / y) << " 0x" << setw(8) <<
setfill('0') << hex << (x / y) << find(const_cast<type_info*>(&typeid(x / y)))
<< endl;
}
cout.flags(ioFlags); cout << setfill(' ');
cout << "x % y " << setw(12) << (x & y) << " 0x" << setw(8) << setfill('0')
<< hex << (x & y) << find(const_cast<type_info*>(&typeid(x & y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "x << y " << setw(12) << (x << y) << " 0x" << setw(8) << setfill('0')
<< hex << (x << y) << find(const_cast<type_info*>(&typeid(x << y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "x >> y " << setw(12) << (x >> y) << " 0x" << setw(8) << setfill('0')
<< hex << (x >> y) << find(const_cast<type_info*>(&typeid(x >> y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "x & y " << setw(12) << (x & y) << " 0x" << setw(8) << setfill('0')
<< hex << (x & y) << find(const_cast<type_info*>(&typeid(x & y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "x | y " << setw(12) << (x | y) << " 0x" << setw(8) << setfill('0')
<< hex << (x | y) << find(const_cast<type_info*>(&typeid(x | y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "x ^ x " << setw(12) << (x ^ y) << " 0x" << setw(8) << setfill('0')
<< hex << (x ^ y) << find(const_cast<type_info*>(&typeid(x ^ y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << endl;
}
void func1(char x, unsigned long y) {
ios_base::fmtflags ioFlags = cout.flags();
cout << "func1(char " << (signed long)x << ", ulong " << y << ')' << endl;
cout << "x + y " << setw(12) << (x + y) << " 0x" << setw(8) << setfill('0')
<< hex << (x + y) << find(const_cast<type_info*>(&typeid(x + y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "x - y " << setw(12) << (x - y) << " 0x" << setw(8) << setfill('0')
<< hex << (x - y) << find(const_cast<type_info*>(&typeid(x - y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "x * y " << setw(12) << (x * y) << " 0x" << setw(8) << setfill('0')
<< hex << (x * y) << find(const_cast<type_info*>(&typeid(x * y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
if (y == 0) {
cout << "x / y " << x << " / 0" << endl;
} else {
cout << "x / y " << setw(12) << (x / y) << " 0x" << setw(8) <<
setfill('0') << hex << (x / y) << find(const_cast<type_info*>(&typeid(x / y)))
<< endl;
}
cout.flags(ioFlags); cout << setfill(' ');
cout << "x % y " << setw(12) << (x & y) << " 0x" << setw(8) << setfill('0')
<< hex << (x & y) << find(const_cast<type_info*>(&typeid(x & y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "x << y " << setw(12) << (x << y) << " 0x" << setw(8) << setfill('0')
<< hex << (x << y) << find(const_cast<type_info*>(&typeid(x << y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "x >> y " << setw(12) << (x >> y) << " 0x" << setw(8) << setfill('0')
<< hex << (x >> y) << find(const_cast<type_info*>(&typeid(x >> y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "x & y " << setw(12) << (x & y) << " 0x" << setw(8) << setfill('0')
<< hex << (x & y) << find(const_cast<type_info*>(&typeid(x & y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "x | y " << setw(12) << (x | y) << " 0x" << setw(8) << setfill('0')
<< hex << (x | y) << find(const_cast<type_info*>(&typeid(x | y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "x ^ x " << setw(12) << (x ^ y) << " 0x" << setw(8) << setfill('0')
<< hex << (x ^ y) << find(const_cast<type_info*>(&typeid(x ^ y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << endl;
}
void func1(char x, long y) {
ios_base::fmtflags ioFlags = cout.flags();
cout << "func1(char " << (signed long)x << ", long " << y << ')' << endl;
cout << "x + y " << setw(12) << (x + y) << " 0x" << setw(8) << setfill('0')
<< hex << (x + y) << find(const_cast<type_info*>(&typeid(x + y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "x - y " << setw(12) << (x - y) << " 0x" << setw(8) << setfill('0')
<< hex << (x - y) << find(const_cast<type_info*>(&typeid(x - y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "x * y " << setw(12) << (x * y) << " 0x" << setw(8) << setfill('0')
<< hex << (x * y) << find(const_cast<type_info*>(&typeid(x * y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
if (y == 0) {
cout << "x / y " << x << " / 0" << endl;
} else {
cout << "x / y " << setw(12) << (x / y) << " 0x" << setw(8) <<
setfill('0') << hex << (x / y) << find(const_cast<type_info*>(&typeid(x / y)))
<< endl;
}
cout.flags(ioFlags); cout << setfill(' ');
cout << "x % y " << setw(12) << (x & y) << " 0x" << setw(8) << setfill('0')
<< hex << (x & y) << find(const_cast<type_info*>(&typeid(x & y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "x << y " << setw(12) << (x << y) << " 0x" << setw(8) << setfill('0')
<< hex << (x << y) << find(const_cast<type_info*>(&typeid(x << y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "x >> y " << setw(12) << (x >> y) << " 0x" << setw(8) << setfill('0')
<< hex << (x >> y) << find(const_cast<type_info*>(&typeid(x >> y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "x & y " << setw(12) << (x & y) << " 0x" << setw(8) << setfill('0')
<< hex << (x & y) << find(const_cast<type_info*>(&typeid(x & y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "x | y " << setw(12) << (x | y) << " 0x" << setw(8) << setfill('0')
<< hex << (x | y) << find(const_cast<type_info*>(&typeid(x | y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "x ^ x " << setw(12) << (x ^ y) << " 0x" << setw(8) << setfill('0')
<< hex << (x ^ y) << find(const_cast<type_info*>(&typeid(x ^ y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << endl;
}
void func0(long x) {
ios_base::fmtflags ioFlags = cout.flags();
string info = find(const_cast<type_info*>(&typeid(x)));
long save = x;
cout << "func0(long " << (long)x << ')' << endl;
cout << "!x " << setw(12) << (!x) << " 0x" << setw(8) << setfill('0') <<
hex << (!x) << find(const_cast<type_info*>(&typeid(!x))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "~x " << setw(12) << (~x) << " 0x" << setw(8) << setfill('0') <<
hex << (~x) << find(const_cast<type_info*>(&typeid(~x))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "+x " << setw(12) << (+x) << " 0x" << setw(8) << setfill('0') <<
hex << (+x) << find(const_cast<type_info*>(&typeid(+x))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "-x " << setw(12) << (-x) << " 0x" << setw(8) << setfill('0') <<
hex << (-x) << find(const_cast<type_info*>(&typeid(-x))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "++x " << setw(12) << (++x) << " 0x" << setw(8) << setfill('0') <<
hex << (long)(++x) << find(const_cast<type_info*>(&typeid(++x))) << endl;
cout.flags(ioFlags); cout << setfill(' '); x = save;
cout << "--x " << setw(12) << (--x) << " 0x" << setw(8) << setfill('0') <<
hex << (long)(--x) << find(const_cast<type_info*>(&typeid(--x))) << endl;
cout.flags(ioFlags); cout << setfill(' '); x = save;
cout << "x++ " << setw(12) << (x++) << " 0x" << setw(8) << setfill('0') <<
hex << (long)(x++) << find(const_cast<type_info*>(&typeid(x++))) << endl;
cout.flags(ioFlags); cout << setfill(' '); x = save;
cout << "x-- " << setw(12) << (x--) << " 0x" << setw(8) << setfill('0') <<
hex << (long)(x--) << find(const_cast<type_info*>(&typeid(x--))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << endl;
}
void func1(long x, char y) {
ios_base::fmtflags ioFlags = cout.flags();
cout << "func1(long " << (signed long)x << ", char " << (unsigned long)y <<
')' << endl;
cout << "x + y " << setw(12) << (x + y) << " 0x" << setw(8) << setfill('0')
<< hex << (x + y) << find(const_cast<type_info*>(&typeid(x + y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "x - y " << setw(12) << (x - y) << " 0x" << setw(8) << setfill('0')
<< hex << (x - y) << find(const_cast<type_info*>(&typeid(x - y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "x * y " << setw(12) << (x * y) << " 0x" << setw(8) << setfill('0')
<< hex << (x * y) << find(const_cast<type_info*>(&typeid(x * y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
if (y == 0) {
cout << "x / y " << x << " / 0" << endl;
} else {
cout << "x / y " << setw(12) << (x / y) << " 0x" << setw(8) <<
setfill('0') << hex << (x / y) << find(const_cast<type_info*>(&typeid(x / y)))
<< endl;
}
cout.flags(ioFlags); cout << setfill(' ');
cout << "x % y " << setw(12) << (x & y) << " 0x" << setw(8) << setfill('0')
<< hex << (x & y) << find(const_cast<type_info*>(&typeid(x & y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "x << y " << setw(12) << (x << y) << " 0x" << setw(8) << setfill('0')
<< hex << (x << y) << find(const_cast<type_info*>(&typeid(x << y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "x >> y " << setw(12) << (x >> y) << " 0x" << setw(8) << setfill('0')
<< hex << (x >> y) << find(const_cast<type_info*>(&typeid(x >> y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "x & y " << setw(12) << (x & y) << " 0x" << setw(8) << setfill('0')
<< hex << (x & y) << find(const_cast<type_info*>(&typeid(x & y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "x | y " << setw(12) << (x | y) << " 0x" << setw(8) << setfill('0')
<< hex << (x | y) << find(const_cast<type_info*>(&typeid(x | y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "x ^ x " << setw(12) << (x ^ y) << " 0x" << setw(8) << setfill('0')
<< hex << (x ^ y) << find(const_cast<type_info*>(&typeid(x ^ y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << endl;
}
void func1(long x, bool y) {
ios_base::fmtflags ioFlags = cout.flags();
cout << "func1(long " << (signed long)x << ", bool " << boolalpha << y << ')'
<< noboolalpha << endl;
cout << "x + y " << setw(12) << (x + y) << " 0x" << setw(8) << setfill('0')
<< hex << (x + y) << find(const_cast<type_info*>(&typeid(x + y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "x - y " << setw(12) << (x - y) << " 0x" << setw(8) << setfill('0')
<< hex << (x - y) << find(const_cast<type_info*>(&typeid(x - y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "x * y " << setw(12) << (x * y) << " 0x" << setw(8) << setfill('0')
<< hex << (x * y) << find(const_cast<type_info*>(&typeid(x * y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
if (y == 0) {
cout << "x / y " << x << " / 0" << endl;
} else {
cout << "x / y " << setw(12) << (x / y) << " 0x" << setw(8) <<
setfill('0') << hex << (x / y) << find(const_cast<type_info*>(&typeid(x / y)))
<< endl;
}
cout.flags(ioFlags); cout << setfill(' ');
cout << "x % y " << setw(12) << (x & y) << " 0x" << setw(8) << setfill('0')
<< hex << (x & y) << find(const_cast<type_info*>(&typeid(x & y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "x << y " << setw(12) << (x << y) << " 0x" << setw(8) << setfill('0')
<< hex << (x << y) << find(const_cast<type_info*>(&typeid(x << y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "x >> y " << setw(12) << (x >> y) << " 0x" << setw(8) << setfill('0')
<< hex << (x >> y) << find(const_cast<type_info*>(&typeid(x >> y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "x & y " << setw(12) << (x & y) << " 0x" << setw(8) << setfill('0')
<< hex << (x & y) << find(const_cast<type_info*>(&typeid(x & y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "x | y " << setw(12) << (x | y) << " 0x" << setw(8) << setfill('0')
<< hex << (x | y) << find(const_cast<type_info*>(&typeid(x | y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "x ^ x " << setw(12) << (x ^ y) << " 0x" << setw(8) << setfill('0')
<< hex << (x ^ y) << find(const_cast<type_info*>(&typeid(x ^ y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << endl;
}
void func1(long x, unsigned char y) {
ios_base::fmtflags ioFlags = cout.flags();
cout << "func1(long " << (signed long)x << ", uchar " << (unsigned long)y <<
')' << endl;
cout << "x + y " << setw(12) << (x + y) << " 0x" << setw(8) << setfill('0')
<< hex << (x + y) << find(const_cast<type_info*>(&typeid(x + y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "x - y " << setw(12) << (x - y) << " 0x" << setw(8) << setfill('0')
<< hex << (x - y) << find(const_cast<type_info*>(&typeid(x - y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "x * y " << setw(12) << (x * y) << " 0x" << setw(8) << setfill('0')
<< hex << (x * y) << find(const_cast<type_info*>(&typeid(x * y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
if (y == 0) {
cout << "x / y " << x << " / 0" << endl;
} else {
cout << "x / y " << setw(12) << (x / y) << " 0x" << setw(8) <<
setfill('0') << hex << (x / y) << find(const_cast<type_info*>(&typeid(x / y)))
<< endl;
}
cout.flags(ioFlags); cout << setfill(' ');
cout << "x % y " << setw(12) << (x & y) << " 0x" << setw(8) << setfill('0')
<< hex << (x & y) << find(const_cast<type_info*>(&typeid(x & y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "x << y " << setw(12) << (x << y) << " 0x" << setw(8) << setfill('0')
<< hex << (x << y) << find(const_cast<type_info*>(&typeid(x << y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "x >> y " << setw(12) << (x >> y) << " 0x" << setw(8) << setfill('0')
<< hex << (x >> y) << find(const_cast<type_info*>(&typeid(x >> y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "x & y " << setw(12) << (x & y) << " 0x" << setw(8) << setfill('0')
<< hex << (x & y) << find(const_cast<type_info*>(&typeid(x & y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "x | y " << setw(12) << (x | y) << " 0x" << setw(8) << setfill('0')
<< hex << (x | y) << find(const_cast<type_info*>(&typeid(x | y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "x ^ x " << setw(12) << (x ^ y) << " 0x" << setw(8) << setfill('0')
<< hex << (x ^ y) << find(const_cast<type_info*>(&typeid(x ^ y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << endl;
}
void func1(long x, unsigned long y) {
ios_base::fmtflags ioFlags = cout.flags();
cout << "func1(long " << (signed long)x << ", ulong " << y << ')' << endl;
cout << "x + y " << setw(12) << (x + y) << " 0x" << setw(8) << setfill('0')
<< hex << (x + y) << find(const_cast<type_info*>(&typeid(x + y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "x - y " << setw(12) << (x - y) << " 0x" << setw(8) << setfill('0')
<< hex << (x - y) << find(const_cast<type_info*>(&typeid(x - y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "x * y " << setw(12) << (x * y) << " 0x" << setw(8) << setfill('0')
<< hex << (x * y) << find(const_cast<type_info*>(&typeid(x * y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
if (y == 0) {
cout << "x / y " << x << " / 0" << endl;
} else {
cout << "x / y " << setw(12) << (x / y) << " 0x" << setw(8) <<
setfill('0') << hex << (x / y) << find(const_cast<type_info*>(&typeid(x / y)))
<< endl;
}
cout.flags(ioFlags); cout << setfill(' ');
cout << "x % y " << setw(12) << (x & y) << " 0x" << setw(8) << setfill('0')
<< hex << (x & y) << find(const_cast<type_info*>(&typeid(x & y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "x << y " << setw(12) << (x << y) << " 0x" << setw(8) << setfill('0')
<< hex << (x << y) << find(const_cast<type_info*>(&typeid(x << y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "x >> y " << setw(12) << (x >> y) << " 0x" << setw(8) << setfill('0')
<< hex << (x >> y) << find(const_cast<type_info*>(&typeid(x >> y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "x & y " << setw(12) << (x & y) << " 0x" << setw(8) << setfill('0')
<< hex << (x & y) << find(const_cast<type_info*>(&typeid(x & y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "x | y " << setw(12) << (x | y) << " 0x" << setw(8) << setfill('0')
<< hex << (x | y) << find(const_cast<type_info*>(&typeid(x | y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "x ^ x " << setw(12) << (x ^ y) << " 0x" << setw(8) << setfill('0')
<< hex << (x ^ y) << find(const_cast<type_info*>(&typeid(x ^ y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << endl;
}
void func1(long x, long y) {
ios_base::fmtflags ioFlags = cout.flags();
cout << "func1(long " << (signed long)x << ", long " << y << ')' << endl;
cout << "x + y " << setw(12) << (x + y) << " 0x" << setw(8) << setfill('0')
<< hex << (x + y) << find(const_cast<type_info*>(&typeid(x + y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "x - y " << setw(12) << (x - y) << " 0x" << setw(8) << setfill('0')
<< hex << (x - y) << find(const_cast<type_info*>(&typeid(x - y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "x * y " << setw(12) << (x * y) << " 0x" << setw(8) << setfill('0')
<< hex << (x * y) << find(const_cast<type_info*>(&typeid(x * y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
if (y == 0) {
cout << "x / y " << x << " / 0" << endl;
} else {
cout << "x / y " << setw(12) << (x / y) << " 0x" << setw(8) <<
setfill('0') << hex << (x / y) << find(const_cast<type_info*>(&typeid(x / y)))
<< endl;
}
cout.flags(ioFlags); cout << setfill(' ');
cout << "x % y " << setw(12) << (x & y) << " 0x" << setw(8) << setfill('0')
<< hex << (x & y) << find(const_cast<type_info*>(&typeid(x & y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "x << y " << setw(12) << (x << y) << " 0x" << setw(8) << setfill('0')
<< hex << (x << y) << find(const_cast<type_info*>(&typeid(x << y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "x >> y " << setw(12) << (x >> y) << " 0x" << setw(8) << setfill('0')
<< hex << (x >> y) << find(const_cast<type_info*>(&typeid(x >> y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "x & y " << setw(12) << (x & y) << " 0x" << setw(8) << setfill('0')
<< hex << (x & y) << find(const_cast<type_info*>(&typeid(x & y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "x | y " << setw(12) << (x | y) << " 0x" << setw(8) << setfill('0')
<< hex << (x | y) << find(const_cast<type_info*>(&typeid(x | y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << "x ^ x " << setw(12) << (x ^ y) << " 0x" << setw(8) << setfill('0')
<< hex << (x ^ y) << find(const_cast<type_info*>(&typeid(x ^ y))) << endl;
cout.flags(ioFlags); cout << setfill(' ');
cout << endl;
}
int main(int argc, char** argv) {
char x1 = -1;
long x2 = -1;
func0((char) 1);
func1(x1, true);
func1(x1, (char) 1);
func1(x1, (unsigned char) 1);
func1(x1, (long) 1);
func1(x1, (unsigned long) 1);
func0((long) 1);
func1(x2, true);
func1(x2, (char) 1);
func1(x2, (unsigned char) 1);
func1(x2, (long) 1);
func1(x2, (unsigned long) 1);
sleep(1);
return 0;
}
More information about the Gcc
mailing list