简体   繁体   English

代码编译过程中的错误

[英]errors during compilation of the code

this is the top portion of my program My code runs perfectly on my Dev-C++ compiler but when i ran the same code on ge edit it showed three errors这是我的程序的顶部 我的代码在我的Dev-C++编译器上完美运行,但是当我在ge edit上运行相同的代码时,它显示了三个错误

1.unused variable d
    double d =round(j);
           ^
2. unused variable d
    double d =round(j);
           ^
3.unused variable i
    float i= (float) round(j);
          ^

how is it possible that the same code works in one compiler but not work in other?同样的代码怎么可能在一个编译器中工作而在另一个编译器中不起作用?

#include <stdio.h>
#include <math.h>

double round(double d);

int main() {
    float j;
    int c = 0;
    printf("how much change is owed? \n");

    scanf("%f", &j);

    double d = round(j);
    float i = (float)round(j);

    while (i < 0) {
        printf("amount of money \n");

        scanf("%f", &j);
        double d = round(j);
        float i = (float)round(j);
    }
    // more code ...

    return 0;
}

These three variables double d, double d, and float i are not used.不使用这三个变量 double d、double d 和 float i。 They are only defined and it is totally unclear why they were defined它们只是被定义了,完全不清楚为什么定义它们

  double d =round(j); // <== ???
  float i= (float) round(j);


    while(i<0)

    {    printf("amount of money \n");

        scanf("%f",&j);
        double d =round(j); // <== ???
        float i= (float) round(j); // <== ???
   }

So the error messages are clear enough.所以错误信息已经足够清楚了。 They are self explained.他们是自我解释的。

I think that in the last marked statement you meant (inside the loop)我认为在最后一个标记的语句中你的意思是(在循环内)

    i= (float) round(j);

Definately.肯定的。

Eg.例如。 Some code is windows-specific and other code is linux specific (dealing with files for example).一些代码是特定于 Windows 的,而其他代码是特定于 linux 的(例如处理文件)。 So code would compile on a windows compiler and not a linux compiler.所以代码将在 Windows 编译器上编译,而不是在 linux 编译器上编译。

There are even different versions of C (look up gnu90 vs. c99 vs. c11) because the specification has changed over time.甚至还有不同版本的 C(查找 gnu90、c99 和 c11),因为规范随着时间的推移而发生了变化。


Your "error" however is a compiler warning you that you are not using 3 variables you assigned.但是,您的“错误”是编译器警告您没有使用分配的 3 个变量。 This is typical of an error so you should go double check.这是典型的错误,因此您应该仔细检查。

It is perfectly valid C and should still compile.它是完全有效的 C 并且应该仍然可以编译。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM