向某人解释为什么在编译时不会自动进行类型转换

Ema*_* Ey 2 c fortran

最近,当我为Fortran程序员编写C简介时,其中一位Fortran程序员向我询问了类型转换.对他而言,在C语言中你必须显式地转换变量而不是让编译器自动为你做这件事并没有多大意义.
我实际上有点难以说明这是好事,因为它有助于避免无意的错误.

你怎么称义这个?

pmg*_*pmg 5

C 不需要演员阵容.转换主要在编译时自动完成.

这是有效的,是惯用的C.

#include <stdio.h>
int main(void) {
    double x;
    int i;

    x = 42;                  /* automatically convert `int` to `double` */
    i = x;                   /* automatically convert `double` to `int` */
    printf("%f\n", i * 1.0); /* automatically convert `int` to `double` */

    printf("%d\n", (int)x);  /* explicit conversion needed */

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

程序中的过多演员表明程序员(可能)使用C++编译器来编译C源文件.演员的一些(很多??)使用是完全错误的.