I’m writing cross-platform x86/x86-64/Itanium code oriented towards high performance and would like to avoid any unnecessary operations, including unneeded type casting.
The code I have calls a function like this:
int theResult = Function(anUInt, 10);
Obviously, the type of 10 value is not specified. And Function is defined like this:
int Function (unsigned int anUInt, int anInt)
{
// ...
}
My assumption is that, with VC++ and GCC targeting x86 machines, the size of an integer literal is 4 bytes, so no type casting would need to be performed when assigning 10 value to anInt parameter while entering the function above (the size of an int value is 4 in almost every data model). Some may not consider it as the ultimate proof of this assumption, but sizeof(1) does return 4 in VC++ and GCC code compiled for the x86 architecture. And I suppose that, if the size of an integer literal on a 64-bit machine was say 8 bytes, the 8 bytes of 10 value would have to be converted into the 4 bytes of anInt parameter, slowing down performance if Function is called very frequently (which is the case in my program).
So would the size of an integer literal be 4 in VC++ and GCC code compiled for a 64-bit architecture, like x86-64 or Itanium, or would it be 8? In other words, what would sizeof(1) return in VC++ and GCC code targeting 64-bit machines? Any special cases for the Itanium (IA-64) architecture?
Edit: changed “untyped integer” to “integer literal”.
There is no such thing as an “untyped integer” in C++. Although you may not specify the type explicity, it does have a type, and that type can be counted upon. The Standard speaks to this:
2.13.1 Integer Literals