If you did
You would get a warning from the compiler (conversion from double to int), so you know you did something wrong!
Actually -- no.
Code:
$ cat implicitcast.c
int n = 1 / 1.5;
int main() {
return 0;
}
$ gcc -W -Wall -ansi -pedantic -g -c implicitcast.c
$
No warnings.
That's the thing with promotion -- most of the time, it's implicit. The compiler does it without informing you it has done so; it's automatic.
It's nearly always automatic when you're going upwards, promoting upwards, because no information will be lost. The other way around, however, can cause problems. That's why my compiler complains about this.
Code:
char c = 123456789;
Code:
implicitcast.c:2: warning: overflow in implicit constant conversion
chars can only hold up to 127 on most platforms, so that int's way too large to fit in a char. (123456789 is an int literal, and it is being implicitly casted to a char.)
Note, however, that my compiler does not mind "char c = 1", which is another implicit cast, though one that cannot overflow . . . .
Yep, it's complicated all right. Welcome to C. . . . actually, in this case it's just me over-explaining things.