用Dev C ++编译C源文件

时间:2009-05-04 16:13:25

标签: c dev-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);       
}

3 个答案:

答案 0 :(得分:4)

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

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

,您需要将其声明为:

double x_plus_one( double x);

您可能还想尝试使用 -traditional 标记进行编译,但我还没有对此进行测试。

答案 1 :(得分:1)

将main更改为int main()。 Neil指出,修改是否正确。

答案 2 :(得分:0)

我认为你是想写这个:

#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
相关问题