C ++ dev to compile the C source file

How can I use Dev C ++ to compile the source C file. I thought it would do it automatically, but for some reason it compiles with a few errors, and I think this is because you need to make changes to compile it file C.

Sample 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);       
}
+3
source share
3 answers

This is the code before ANSI. I'm not sure if the gcc compiler supports it, and in any case, using it is bad. 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 can also try compiling with the -traditional flag , but I have not tested this.

+4
source

main int main(). , .

+1

, :

#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
0

Source: https://habr.com/ru/post/1707609/


All Articles