用GCC输出带C源代码注释的汇编列表文件
我们都知道gcc的-S开关可以用来生成汇编代码,
但有时候,单有汇编文件是不够的,我们希望的是将C语言程序的源代码和汇编语言文本交错在一起查看,
这是LISTING功能,在gcc中并没有专门的FAQ说明,
区区在网上查了很多资料才知道怎么实现,所以特此记下。
gcc -c -g -Wa,-adlhn ee.c > ee.anno.s
由此生成的ee.anno.s即是ee.c对应的C与汇编混排的列表
又如C程序
/* EE */
#include<stdio.h>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<windows.h>
int main(int argc, char **argv)
{
char * p = "TO STDOUT";
int ic = (int)GetStdHandle(STD_OUTPUT_HANDLE);
printf("%d\n", ic);
WriteFile(ic, p, strlen(p), &ic, NULL);
return 0;
}
可以生成
1
.file
"ee.c"
4
.text
5
Ltext0:
4222
.section .rdata,"dr"
4223
LC0:
4224 0000 544F2053
.ascii "TO STDOUT\0"
4224 54444F55
4224 5400
4225
LC1:
4226 000a 25640A00
.ascii "%d\12\0"
4227 000e 0000
.text
4231
.globl _main
4233
_main:
1:ee.c **** /* EE */
2:ee.c **** #include<stdio.h>
3:ee.c **** #include<stdio.h>
4:ee.c **** #include<string.h>
5:ee.c &nbs
相关文档:
http://www.cnblogs.com/hoodlum1980/archive/2007/08/15/857067.html
题干:输入两个较大的数,输出相乘的结果。
意思也就是两个数很大,超出了int的存储范围。
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define N 100
void GetDigits( ......
通常,在C语言的头文件中经常可以看到类似下面这种形式的代码:
#ifdef __cplusplus
extern "C" {
#endif
/**** some declaration or so *****/
#ifdef __cplusplus
}
#endif /* end of __cplusplus */
那么,这种写法什么用呢?实际上,这是为了让CPP能够与C接口而采用的一种语法形式。之所以采用这种方式 ......
#include <stdio.h>
#include <stdlib.h>
#define SIZE 17
void reverse(int start, int end);
int data[SIZE] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17};
int main(void)
{
int i = 5;
reverse(0, i - 1);
reverse(i, SIZE-1);
reverse(0, SIZE-1);
return ......
在C语言里,全局变量如果不初始化的话,默认为0,也就是说在全局空间里:
int x =0; 跟 int x; 的效果看起来是一样的。但其实这里面的差别很大,强烈建议大家所有的全局变量都要初始化,他们的主要差别如下:
编译器在编译的时候针对这两种情况会产生两种符号放在目标文件的符号表中,对于初始化的,叫强符号,未初始化的 ......