开发 C++ 编译C源文件
如何使用 Dev C++ 编译 C 源文件。 我以为它会自动执行此操作,但由于某种原因,它编译时出现了几个错误,我认为这是因为您必须对其进行更改才能编译 C 文件。
示例测试代码:
#include <stdio.h>
main ()
{ int i,j;
double x,x_plus_one();
char ch;
i = 0;
x = 0;
printf (" %f", x_plus_one(x));
printf (" %f", x);
j = resultof (i);
printf (" %d",j);
}
double x_plus_one(x)
double x;
{
x = x + 1;
return (x);
}
resultof (j)
int j;
{
return (2*j + 3);
}
How can I use Dev C++ to compile C source file. I thought it would automatically do it, but for some reason it compiles with several errors and I think its because you have to make changes for it to compile a C file.
Example test code:
#include <stdio.h>
main ()
{ int i,j;
double x,x_plus_one();
char ch;
i = 0;
x = 0;
printf (" %f", x_plus_one(x));
printf (" %f", x);
j = resultof (i);
printf (" %d",j);
}
double x_plus_one(x)
double x;
{
x = x + 1;
return (x);
}
resultof (j)
int j;
{
return (2*j + 3);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
那是 ANSI 之前的代码。 我不确定 gcc 编译器是否支持它,并且无论如何使用它都是不好的做法。 将您的函数更改为:
您需要将其声明为:
您可能还想尝试使用 -traditional 标志进行编译,但我还没有对此进行测试。
That is pre-ANSI code. I'm not sure the gcc compiler supports it, and in any case it is bad practice to use it. Change your function to:
and you will need to declare it as:
You may also want to try compiling with the -traditional flag, but I haven't tested this.
也将 main 更改为 int main()。 并按照尼尔指出的进行修改。
Change main to int main() as well. And Do the modification as Neil pointed out.
我认为你试图写这个:
保存为 main.cpp 并进行编译
i think you were trying to write this:
save as main.cpp and for compiling