T
tobiasoed
Hello!
I have the following piece of code:
#include <stdio.h>
int main(void){
unsigned int u;
int i1, i2;
double d1,d2;
u = 0;
i1 = u - 1;
i2 = (signed int) u - 1;
d1 = u - 1;
d2 = (signed int) u - 1;
printf("i1 = %d, i2 = %d, d1 = %f, d2 = %f\n",i1,i2,d1,d2);
}
and don't understand the output:
tobsbox:~/C$ cc -std=c99 -Wall -W -pedantic unsigned.c && ./a.out
i1 = -1, i2 = -1, d1 = 4294967295.000000, d2 = -1.000000
It looks like u is promoted to signed int for i2 but not d2. Is
this normal or is it a compiler bug?
Tobias
ps: My compiler is
cc (GCC) 3.4.3 20050227 (Red Hat 3.4.3-22.fc3)
Copyright (C) 2004 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is
NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.
I have the following piece of code:
#include <stdio.h>
int main(void){
unsigned int u;
int i1, i2;
double d1,d2;
u = 0;
i1 = u - 1;
i2 = (signed int) u - 1;
d1 = u - 1;
d2 = (signed int) u - 1;
printf("i1 = %d, i2 = %d, d1 = %f, d2 = %f\n",i1,i2,d1,d2);
}
and don't understand the output:
tobsbox:~/C$ cc -std=c99 -Wall -W -pedantic unsigned.c && ./a.out
i1 = -1, i2 = -1, d1 = 4294967295.000000, d2 = -1.000000
It looks like u is promoted to signed int for i2 but not d2. Is
this normal or is it a compiler bug?
Tobias
ps: My compiler is
cc (GCC) 3.4.3 20050227 (Red Hat 3.4.3-22.fc3)
Copyright (C) 2004 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is
NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.