C 编译

C语言编译过程
C语言编译过程

gcc 编译参数
这里写图片描述

源文件
a.c

#include<stdio.h>

int main(){
    // 九九乘法表
    int i,j;
    for(i=1; i<=9; i++) {
        for(j=1; j<=i; j++) {
            printf("%dx%d=%2d ", j, i, i*j);
        }
        printf("\n");
    }
}

预编译

预编译将#include包含的头文件内容替换到C文件中,同时删除代码中的注释部分

gcc -E -o a.e a.c

a.e 部分内容已删除

typedef unsigned char __u_char;
typedef unsigned short int __u_short;
typedef unsigned int __u_int;
typedef unsigned long int __u_long;


typedef signed char __int8_t;
typedef unsigned char __uint8_t;
typedef signed short int __int16_t;
typedef unsigned short int __uint16_t;
typedef signed int __int32_t;
typedef unsigned int __uint32_t;


extern int fprintf (FILE *__restrict __stream,
      const char *__restrict __format, ...);


extern int printf (const char *__restrict __format, ...);

extern int sprintf (char *__restrict __s,
      const char *__restrict __format, ...) __attribute__ ((__nothrow__));


int main(){

 int i,j;
 for(i=1; i<=9; i++) {
  for(j=1; j<=i; j++) {
   printf("%dx%d=%2d ", j, i, i*j);
  }
  printf("\n");
 }
}

变量分配

int a = 0; 全局初始化区   
char *p1; 全局未初始化区   
main()   {    
    int b; 栈
    char s[] = "abc"; 栈
    char *p2; 栈
    char *p3 = "123456"; 123456\0在常量区,p3在栈上。
    static int c =0; 全局(静态)初始化区
    p1 = (char *)malloc(10);
    p2 = (char *)malloc(20);    分配得来得1020字节的区域就在堆区。
    strcpy(p1, "123456"); 123456\0放在常量区,编译器可能会将它与p3所指向的"123456"优化成一个地方。
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值