代码之家  ›  专栏  ›  技术社区  ›  TStamper

开发C++编译C源文件

  •  3
  • TStamper  · 技术社区  · 17 年前

    示例测试代码:

     #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 回复  |  直到 17 年前
        1
  •  4
  •   anon anon    17 年前

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

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

    您需要将其声明为:

    double x_plus_one( double x);
    

    您可能还想尝试使用 -传统 国旗,但我还没有测试过。

        2
  •  1
  •   user100991 user100991    17 年前

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

        3
  •  0
  •   Amir    10 年前

    我想你是想写这个:

    #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
    
    推荐文章