Floating constants in C

I have a question about floating constants in C.

In Java, the default type of floating point constants is double, so the following will result in a compilation error in java:

float f = 100.0;   // we either need to uses type case operator or put f at the end of the number constant.

This is due to the fact that floating-point constants are of type double by default and casting from double to float without a cast operator is a mistake, so we need to either add a case statement or put f at the end of the number.

So, why does this not cause an error in C, because floating-point constants are of type float by default, or because the compiler performs an implicit conversion with a down conversion (which does not require a type in C)

+3
source share
3 answers

C double, double float ( , : , a float, undefined).

float, f .

+8

C. . §6.4.4.2 :

, :

§ 6: 3.1.5:

" double float, float , , (. 6.3.1.8) , . , , , , . , , ".

§6: 5.16:

" [...]"

§6: 5.16.1:

" (=) , , ".

+4

C . , , .

gcc -Wconversion ( -Wall) downcasting (, , ).

: 'float' "double"

+2

Source: https://habr.com/ru/post/1746807/


All Articles