1、GCC编译过程GCC词法分析,语法分析,语义分析答案:一、 gcc编译过程分为四段:预处理、编译、汇编、链接预处理:gcc -E hello.c -o hello.i 参数-E表示只进行预处理或者也可以使用以下指令完成预处理过程。 将所有的#define删除,并且展开所有的宏定义 处理所有的条件预编译指令,比如#if,#ifdef,#elif,#else,#endif等。 处理#include预编译指令,将被包含的文件插入到该预编译指令的位置。 删除所有注释“/”和”/*/”. 添加行号和文件标识,以便编译时产生调试用的行号及编译错误警告行号。 保留所有的#pragma编译器指令,因为编译器需
2、要使用它们。预处理结果:# 1 hello.c# 1 # 1 # 1 hello.c# 1 /usr/include/stdio.h 1 3 4# 28 /usr/include/stdio.h 3 4# 1 /usr/include/features.h 1 3 4# 363 /usr/include/features.h 3 4# 1 /usr/include/sys/cdefs.h 1 3 4# 372 /usr/include/sys/cdefs.h 3 4# 1 /usr/include/bits/wordsize.h 1 3 4# 373 /usr/include/sys/cdef
3、s.h 2 3 4# 364 /usr/include/features.h 2 3 4# 387 /usr/include/features.h 3 4# 1 /usr/include/gnu/stubs.h 1 3 4# 1 /usr/include/bits/wordsize.h 1 3 4# 5 /usr/include/gnu/stubs.h 2 3 4# 1 /usr/include/gnu/stubs-32.h 1 3 4# 8 /usr/include/gnu/stubs.h 2 3 4# 388 /usr/include/features.h 2 3 4# 29 /usr/i
4、nclude/stdio.h 2 3 4# 1 /usr/lib/gcc/i686-redhat-linux/4.6.2/include/stddef.h 1 3 4# 212 /usr/lib/gcc/i686-redhat-linux/4.6.2/include/stddef.h 3 4typedef unsigned int size_t;# 35 /usr/include/stdio.h 2 3 4# 1 /usr/include/bits/types.h 1 3 4# 28 /usr/include/bits/types.h 3 4# 1 /usr/include/bits/word
5、size.h 1 3 4# 29 /usr/include/bits/types.h 2 3 4typedef 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 _uin
6、t16_t;typedef signed int _int32_t;typedef unsigned int _uint32_t;_extension_ typedef signed long long int _int64_t;_extension_ typedef unsigned long long int _uint64_t;_extension_ typedef long long int _quad_t;_extension_ typedef unsigned long long int _u_quad_t;# 131 /usr/include/bits/types.h 3 4#
7、1 /usr/include/bits/typesizes.h 1 3 4# 132 /usr/include/bits/types.h 2 3 4_extension_ typedef _u_quad_t _dev_t;_extension_ typedef unsigned int _uid_t;_extension_ typedef unsigned int _gid_t;_extension_ typedef unsigned long int _ino_t;_extension_ typedef _u_quad_t _ino64_t;_extension_ typedef unsig
8、ned int _mode_t;_extension_ typedef unsigned int _nlink_t;_extension_ typedef long int _off_t;_extension_ typedef _quad_t _off64_t;_extension_ typedef int _pid_t;_extension_ typedef struct int _val2; _fsid_t;_extension_ typedef long int _clock_t;_extension_ typedef unsigned long int _rlim_t;_extensi
9、on_ typedef _u_quad_t _rlim64_t;_extension_ typedef unsigned int _id_t;_extension_ typedef long int _time_t;_extension_ typedef unsigned int _useconds_t;_extension_ typedef long int _suseconds_t;_extension_ typedef int _daddr_t;_extension_ typedef long int _swblk_t;_extension_ typedef int _key_t;_ex
10、tension_ typedef int _clockid_t;_extension_ typedef void * _timer_t;_extension_ typedef long int _blksize_t;_extension_ typedef long int _blkcnt_t;_extension_ typedef _quad_t _blkcnt64_t;_extension_ typedef unsigned long int _fsblkcnt_t;_extension_ typedef _u_quad_t _fsblkcnt64_t;_extension_ typedef
11、 unsigned long int _fsfilcnt_t;_extension_ typedef _u_quad_t _fsfilcnt64_t;_extension_ typedef int _ssize_t;typedef _off64_t _loff_t;typedef _quad_t *_qaddr_t;typedef char *_caddr_t;_extension_ typedef int _intptr_t;_extension_ typedef unsigned int _socklen_t;# 37 /usr/include/stdio.h 2 3 4# 45 /usr
12、/include/stdio.h 3 4struct _IO_FILE;typedef struct _IO_FILE FILE;# 65 /usr/include/stdio.h 3 4typedef struct _IO_FILE _FILE;# 75 /usr/include/stdio.h 3 4# 1 /usr/include/libio.h 1 3 4# 32 /usr/include/libio.h 3 4# 1 /usr/include/_G_config.h 1 3 4# 15 /usr/include/_G_config.h 3 4# 1 /usr/lib/gcc/i686
13、-redhat-linux/4.6.2/include/stddef.h 1 3 4# 16 /usr/include/_G_config.h 2 3 4# 1 /usr/include/wchar.h 1 3 4# 83 /usr/include/wchar.h 3 4typedef struct int _count; union unsigned int _wch; char _wchb4; _value; _mbstate_t;# 21 /usr/include/_G_config.h 2 3 4typedef struct _off_t _pos; _mbstate_t _state
14、; _G_fpos_t;typedef struct _off64_t _pos; _mbstate_t _state; _G_fpos64_t;# 53 /usr/include/_G_config.h 3 4typedef int _G_int16_t _attribute_ (_mode_ (_HI_);typedef int _G_int32_t _attribute_ (_mode_ (_SI_);typedef unsigned int _G_uint16_t _attribute_ (_mode_ (_HI_);typedef unsigned int _G_uint32_t _
15、attribute_ (_mode_ (_SI_);# 33 /usr/include/libio.h 2 3 4# 53 /usr/include/libio.h 3 4# 1 /usr/lib/gcc/i686-redhat-linux/4.6.2/include/stdarg.h 1 3 4# 40 /usr/lib/gcc/i686-redhat-linux/4.6.2/include/stdarg.h 3 4typedef _builtin_va_list _gnuc_va_list;# 54 /usr/include/libio.h 2 3 4# 172 /usr/include/
16、libio.h 3 4struct _IO_jump_t; struct _IO_FILE;# 182 /usr/include/libio.h 3 4typedef void _IO_lock_t;struct _IO_marker struct _IO_marker *_next; struct _IO_FILE *_sbuf; int _pos;# 205 /usr/include/libio.h 3 4;enum _codecvt_result _codecvt_ok, _codecvt_partial, _codecvt_error, _codecvt_noconv;# 273 /u
17、sr/include/libio.h 3 4struct _IO_FILE int _flags; char* _IO_read_ptr; char* _IO_read_end; char* _IO_read_base; char* _IO_write_base; char* _IO_write_ptr; char* _IO_write_end; char* _IO_buf_base; char* _IO_buf_end; char *_IO_save_base; char *_IO_backup_base; char *_IO_save_end; struct _IO_marker *_ma
18、rkers; struct _IO_FILE *_chain; int _fileno; int _flags2; _off_t _old_offset; unsigned short _cur_column; signed char _vtable_offset; char _shortbuf1; _IO_lock_t *_lock;# 321 /usr/include/libio.h 3 4 _off64_t _offset;# 330 /usr/include/libio.h 3 4 void *_pad1; void *_pad2; void *_pad3; void *_pad4;
19、size_t _pad5; int _mode; char _unused215 * sizeof (int) - 4 * sizeof (void *) - sizeof (size_t);typedef struct _IO_FILE _IO_FILE;struct _IO_FILE_plus;extern struct _IO_FILE_plus _IO_2_1_stdin_;extern struct _IO_FILE_plus _IO_2_1_stdout_;extern struct _IO_FILE_plus _IO_2_1_stderr_;# 366 /usr/include/
20、libio.h 3 4typedef _ssize_t _io_read_fn (void *_cookie, char *_buf, size_t _nbytes);typedef _ssize_t _io_write_fn (void *_cookie, _const char *_buf, size_t _n);typedef int _io_seek_fn (void *_cookie, _off64_t *_pos, int _w);typedef int _io_close_fn (void *_cookie);# 418 /usr/include/libio.h 3 4exter
21、n int _underflow (_IO_FILE *);extern int _uflow (_IO_FILE *);extern int _overflow (_IO_FILE *, int);# 462 /usr/include/libio.h 3 4extern int _IO_getc (_IO_FILE *_fp);extern int _IO_putc (int _c, _IO_FILE *_fp);extern int _IO_feof (_IO_FILE *_fp) _attribute_ (_nothrow_);extern int _IO_ferror (_IO_FIL
22、E *_fp) _attribute_ (_nothrow_);extern int _IO_peekc_locked (_IO_FILE *_fp);extern void _IO_flockfile (_IO_FILE *) _attribute_ (_nothrow_);extern void _IO_funlockfile (_IO_FILE *) _attribute_ (_nothrow_);extern int _IO_ftrylockfile (_IO_FILE *) _attribute_ (_nothrow_);# 492 /usr/include/libio.h 3 4e
23、xtern int _IO_vfscanf (_IO_FILE * _restrict, const char * _restrict, _gnuc_va_list, int *_restrict);extern int _IO_vfprintf (_IO_FILE *_restrict, const char *_restrict, _gnuc_va_list);extern _ssize_t _IO_padn (_IO_FILE *, int, _ssize_t);extern size_t _IO_sgetn (_IO_FILE *, void *, size_t);extern _of
24、f64_t _IO_seekoff (_IO_FILE *, _off64_t, int, int);extern _off64_t _IO_seekpos (_IO_FILE *, _off64_t, int);extern void _IO_free_backup_area (_IO_FILE *) _attribute_ (_nothrow_);# 76 /usr/include/stdio.h 2 3 4typedef _gnuc_va_list va_list;# 91 /usr/include/stdio.h 3 4typedef _off_t off_t;# 103 /usr/i
25、nclude/stdio.h 3 4typedef _ssize_t ssize_t;typedef _G_fpos_t fpos_t;# 165 /usr/include/stdio.h 3 4# 1 /usr/include/bits/stdio_lim.h 1 3 4# 166 /usr/include/stdio.h 2 3 4extern struct _IO_FILE *stdin;extern struct _IO_FILE *stdout;extern struct _IO_FILE *stderr;extern int remove (_const char *_filena
26、me) _attribute_ (_nothrow_);extern int rename (_const char *_old, _const char *_new) _attribute_ (_nothrow_);extern int renameat (int _oldfd, _const char *_old, int _newfd, _const char *_new) _attribute_ (_nothrow_);extern FILE *tmpfile (void) ;# 212 /usr/include/stdio.h 3 4extern char *tmpnam (char
27、 *_s) _attribute_ (_nothrow_) ;extern char *tmpnam_r (char *_s) _attribute_ (_nothrow_) ;# 230 /usr/include/stdio.h 3 4extern char *tempnam (_const char *_dir, _const char *_pfx) _attribute_ (_nothrow_) _attribute_ (_malloc_) ;extern int fclose (FILE *_stream);extern int fflush (FILE *_stream);# 255
28、 /usr/include/stdio.h 3 4extern int fflush_unlocked (FILE *_stream);# 269 /usr/include/stdio.h 3 4extern FILE *fopen (_const char *_restrict _filename, _const char *_restrict _modes) ;extern FILE *freopen (_const char *_restrict _filename, _const char *_restrict _modes, FILE *_restrict _stream) ;# 2
29、98 /usr/include/stdio.h 3 4# 309 /usr/include/stdio.h 3 4extern FILE *fdopen (int _fd, _const char *_modes) _attribute_ (_nothrow_) ;# 322 /usr/include/stdio.h 3 4extern FILE *fmemopen (void *_s, size_t _len, _const char *_modes) _attribute_ (_nothrow_) ;extern FILE *open_memstream (char *_bufloc, size_t *_sizeloc) _attribute_ (_nothrow_) ;extern void setbuf (FILE *_restrict _stream, char *_restrict _buf) _attribute_ (_nothrow_);extern int setvbuf (FILE *_restrict
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1