内联函数23.6.13

内敛函数强制

#include<stdio.h>

static inline __attribute__((noinline)) void fun1();
static inline __attribute__((always_inline)) void fun2();

static inline __attribute__((noinline)) void fun1(){
        printf("77");
}
static inline __attribute__((always_inline)) void fun2()
{
        printf("66");
}

void main(void){
    fun1();
    fun2();

}

对上面文件进行编译,后使用objdump反编译进行查看,可以看到
fun1和fun2的区别,将fun1的__attribute__((noinline))删除结果也是相同的,但是不会报错。

$ gcc -g inline.c -o inline.o
//使用noinline会报错但是不会影响编译

$ objdump inline.o -S -j .text

/*
000000000000064a <fun1>://noinline函数在外
#include<stdio.h>

static inline __attribute__((noinline)) void fun1();
static inline __attribute__((always_inline)) void fun2();

static inline __attribute__((noinline)) void fun1(){
 64a:	55                   	push   %rbp
 64b:	48 89 e5             	mov    %rsp,%rbp
		printf("77");
 64e:	48 8d 3d bf 00 00 00 	lea    0xbf(%rip),%rdi        # 714 <_IO_stdin_used+0x4>
 655:	b8 00 00 00 00       	mov    $0x0,%eax
 65a:	e8 c1 fe ff ff       	callq  520 <printf@plt>
}
 65f:	90                   	nop
 660:	5d                   	pop    %rbp
 661:	c3                   	retq   

0000000000000662 <main>:
static inline __attribute__((always_inline)) void fun2()
{
		printf("66");
}

void main(void){
 662:	55                   	push   %rbp
 663:	48 89 e5             	mov    %rsp,%rbp
	fun1();
 666:	b8 00 00 00 00       	mov    $0x0,%eax
 66b:	e8 da ff ff ff       	callq  64a <fun1>
		printf("66");
 670:	48 8d 3d a0 00 00 00 	lea    0xa0(%rip),%rdi        # 717 <_IO_stdin_used+0x7>
 677:	b8 00 00 00 00       	mov    $0x0,%eax
 67c:	e8 9f fe ff ff       	callq  520 <printf@plt>
	fun2();

}
 681:	90                   	nop
 682:	5d                   	pop    %rbp
 683:	c3                   	retq   
 684:	66 2e 0f 1f 84 00 00 	nopw   %cs:0x0(%rax,%rax,1)
 68b:	00 00 00 
 68e:	66 90                	xchg   %ax,%ax


fun2函数在main函数内

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值