Is there any other promotion besides promotion of 0 from int to double in first line?
double d=-1./0;
unsigned int *pd = (unsigned int *)&d;
printf("1:%08x\n",*++pd);
printf("2:%08x",*--pd);
Is there any other promotion besides promotion of 0 from int to double in first line?
double d=-1./0;
unsigned int *pd = (unsigned int *)&d;
printf("1:%08x\n",*++pd);
printf("2:%08x",*--pd);
.. besides promotion of 0 from int to double ..
Well, the standard doesn't use the term "promotion" for this. The standard uses the term "Usual arithmetic conversions".
The term "promotion" in the standard is related to "integer promotion" and tells how different integer types are converted to a common integer type before applying the operator used..
BTW: Making a unsigned int
pointer point to a double
object and dereferencing it, is a violation of the strict aliasing rule.
Edit based on comment from Ian Abbott:
The term "promotion" is also used for "default argument promotions", which includes promotion of float to double for the variable arguments of a function or the arguments of a function without a prototype.
Is there any other promotion besides promotion of 0 from int to double in first line?
No.
1.
or 1.0
is a constant of type double
. -
does not change the type of the operand, since it was not a small integer type but a double
.0
is of type int
and promoted to double
as part of the usual arithmetic conversions./
has type double
. This is the same type as variable d
, so no lvalue conversion takes place.Details here: Implicit type promotion rules
Unrelated to your question, de-referencing the double d
as an integer type invokes undefined behavior bugs: it's a violation of the strict aliasing rule. Doing pointer arithmetic beyond the end of the pointed-at type is also undefined behavior.