(一)Ubuntu系统下,用gcc编写程序
1.编写c程序
(1)编写main.c
#include"sub1.h"
int main()
{
int x=8,y=3;
float c;
c= x2x(x,y);//调用子函数
printf("%.2f\n",c);
return 0;
}
(2)编写sub1.c
#include"sub1.h"
float x2x(int a,int b)//定义一个算数运算函数
{
float c;
c=(float)a/b;
return c;//返回c的值
}
(3)编写sub1.h
#ifndef __SUB1_H
#define __SUB1_H
#include<stdio.h>
float x2x(int a,int b);
#endif
2.gcc编译流程
(1)预处理
命令:gcc -E hello.c -o hello.i
作用:用于对源代码进行宏替换、文件包含和条件编译等预处理操作,得到一个C程序,以“.i”作为扩展名。
(2)编译
命令:gcc -S hello.i