易截截图软件、单文件、免安装、纯绿色、仅160KB

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++——小编谈C语言函数那些事(24)

C程序是由一组或是变量或是函数的外部对象组成的。 函数是一个自我包含的完成一定相关功能的执行代码段。下面小编和大家分享下C语言中的函数。
 
1.   setvect函数
setvect函数的功能是设置中断矢量入口,其用法为:void setvect(int intr_num, void interrupt(*isr)());程序实例如下:
#include <st ......

C/C++——小编谈C语言函数那些事(26)

C程序是由一组或是变量或是函数的外部对象组成的。 函数是一个自我包含的完成一定相关功能的执行代码段。下面小编和大家分享下C语言中的函数。
 
1.   sopen函数
sopen函数的功能是打开一共享文件,其用法为:int sopen(char *pathname, int access, int shflag, int permiss);程序实例如下:
#include ......

C/C++题集

转自: 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 ......

DAY3|编个"hello world"的C程序先~

今天要编个最简单的"hello world"的C程序,算是初步感受下Linux中的编程环境,涉及以下3个步骤:
1. 先在"vim"里编写源文件;
2. 然后再用"gcc"编译生成"hello"的可执行文件;
3. 运行"hello",看看效果。
那么开始吧!
1. vim
vim hello.c
i
#include <stdio.h>
int
main (void)
{
printf ("hello.\n" ......

c指针详解

 第一章 概念
指针是一个特殊的变量,它里面存储的数值被解释成为内存里的一个地址。要搞清一个指针需要搞清指针的四方面的内容:指针的类型,指针所指向的类型,指针的值或者叫指针所指向的内存区,还有指针本身所占据的内存区。让我们分别说明。
先声明几个指针放着做例子:
例一:
(1)int *ptr;
(2)char ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号