开发 C++ 编译C源文件

发布于 2024-07-18 02:22:55 字数 491 浏览 8 评论 0原文

如何使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

冷弦 2024-07-25 02:22:55

那是 ANSI 之前的代码。 我不确定 gcc 编译器是否支持它,并且无论如何使用它都是不好的做法。 将您的函数更改为:

double x_plus_one( double x) {
  x = x + 1;
  return (x);     
}

您需要将其声明为:

double x_plus_one( double x);

您可能还想尝试使用 -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:

double x_plus_one( double x) {
  x = x + 1;
  return (x);     
}

and you will need to declare it as:

double x_plus_one( double x);

You may also want to try compiling with the -traditional flag, but I haven't tested this.

乖不如嘢 2024-07-25 02:22:55

也将 main 更改为 int main()。 并按照尼尔指出的进行修改。

Change main to int main() as well. And Do the modification as Neil pointed out.

枯叶蝶 2024-07-25 02:22:55

我认为你试图写这个:

#include <stdio.h>

double x_plus_one(double x);
int resultof(int j);


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(double x)

//double x;

{
  x = x + 1;
  return (x);
}


int resultof (int j)             

//int j;

{
   return (2*j + 3);       
}

保存为 main.cpp 并进行编译

g++.exe -D__DEBUG__ -c main.cpp -o main.o -I"C:/Program Files/CodeBlocks/MinGW/include" -g3

g++.exe -D__DEBUG__ main.o -o Project1.exe -L"C:/Program Files/CodeBlocks/MinGW/lib" -static-libgcc -mwindows -g3


Compilation results...
--------
- Errors: 0
- Warnings: 0
- Output Filename: F:\My Folder\C++ projects\test01\Project1.exe
- Output Size: 38.990234375 KiB
- Compilation Time: 1.92s

i think you were trying to write this:

#include <stdio.h>

double x_plus_one(double x);
int resultof(int j);


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(double x)

//double x;

{
  x = x + 1;
  return (x);
}


int resultof (int j)             

//int j;

{
   return (2*j + 3);       
}

save as main.cpp and for compiling

g++.exe -D__DEBUG__ -c main.cpp -o main.o -I"C:/Program Files/CodeBlocks/MinGW/include" -g3

g++.exe -D__DEBUG__ main.o -o Project1.exe -L"C:/Program Files/CodeBlocks/MinGW/lib" -static-libgcc -mwindows -g3


Compilation results...
--------
- Errors: 0
- Warnings: 0
- Output Filename: F:\My Folder\C++ projects\test01\Project1.exe
- Output Size: 38.990234375 KiB
- Compilation Time: 1.92s
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文