ISO/IEC 9899:TC3 Committee Draft — Septermber 7, 2007 WG14/N1256
…
6.5.15 Conditional operator
…
If both the second and third operands have arithmetic type, the result type that would be determined by the usual arithmetic conversions, were they applied to those two operands, is the type of the result.
i.e.
#include <stdio.h>
void SetLong (long foo)
{
fprintf(stderr, "Got a long of %ld\n", foo);
}
int main(void)
{
int a = -10;
unsigned int b = 10;
/*int converted to long*/
SetLong( a );
/*unsigned int converted to long*/
SetLong( b );
/* int and unsigned int results converted to unsigned int,
unsigned int then converted to long. i.e. totally different
from if (1) SetLong(a); else SetLong(b); */
SetLong( 1 ? a : b );
return 0;
}
On 32bit Linux long and int are the same size, so it doesn’t matter and we get -10, 10, -10, on 64bit they’re not and so results in -10, 10 and 4294967286