extern "C" 详解
extern "C" 详解
在C++中,为了支持重载机制,在编译生成汇编代码时,函数的名字要加入函数的参数类型或者返回值类型等信息
在C中,因没有重载机制,编译后的代码只是简单的函数名字而已,不加入其他的信息
1. 不加入extern "C"
testexternc.cpp
int mytest(void)
{
int a=10,b=20;
int c=a+b;
return c;
}
Command: g++ -S testexternc.cpp或者gcc -S testexternc.cpp
Generated file: testexternc.s
.file "testexternc.cpp"
.text
.align 2
.globl _Z6mytestv
.type _Z6mytestv, @function
_Z6mytestv:
.LFB2:
pushl %ebp
.LCFI0:
movl %esp, %ebp
.LCFI1:
subl $16, %esp
.LCFI2:
movl $10, -12(%ebp)
movl $20, -8(%ebp)
movl -8(%ebp), %eax
addl -12(%ebp), %eax
movl %eax, -4(%ebp)
movl -4(%ebp), %eax
leave
ret
.LFE2:
.size _Z6mytestv, .-_Z6mytestv
.globl __gxx_personality_v0
相关文档:
C程序是由一组或是变量或是函数的外部对象组成的。 函数是一个自我包含的完成一定相关功能的执行代码段。下面小编和大家分享下C语言中的函数。
1. setvect函数
setvect函数的功能是设置中断矢量入口,其用法为:void setvect(int intr_num, void interrupt(*isr)());程序实例如下:
#include <st ......
转自: http://hi.baidu.com/elliott_hdu/blog/item/411421dd5bf8dfe977c63876.html
1.下列程序的输出结果为:(B)
#include<iostream.h>
void main()
{
char* a[ ] = { "hello", "the", "world"};
char** pa = a;
&nbs ......
1.MFC中的方法:(C++)
CFileStatus status;
CFile::GetStatus("D:\\test.txt",status);
long lSizeOfFile;
lSizeOfFile = status.m_size;
lSizeOfFile的值就是D:\\test.txt文件的大小
2.标准C获得文件大小的5种方法
(注意:"__FILE__"指的是当前文件,你可以改为有效路径的目标文件,比如"D:\\test.txt")
#i ......
(1)
数组名的内涵在于其指代实体是一种数据结构,这种数据结构就是数组;
(2)
数组名的外延在于其可以转换为指向其指代实体的指针,而且是一个指针常量;
(3)
指向数组的指针则是另外一种变量类型(在WIN32平台下,长度为4),仅仅意味着数组的存放地址
(4)
数组名作为函数形参时,在函数体内,其失去了本身的内涵 ......