C++笔记-初步窥探全局函数在Debug、Release的地址

目录

 

 

前言

代码与实例


 

前言

这里做个笔记,此笔记最后的结论是在各个编译器或各种优化中,函数地址也会被编译器优化。个人觉得搞技术这一块,学着学着就有了交集,在此记录下,没准以后还真有机会接触到反汇编这种项目呢。

 

 

代码与实例

如下面的代码:

#include <iostream>
using namespace std;

void test1(){

	cout << "This is test1() called!" << endl;
	cout << "1111111" << endl;
	int a = 1,b = 2, c = 3, d = 4;
	cout << a + b +3 +d;
}

void test2(char *str){

	char buf[128];
	strcpy(buf, str);
	cout << "This is test2() called : " << buf << endl;
}

void test3(){

	cout << "test3" << endl;
}

void test4(){

	cout << "test4" << endl;
}

void test5(){

	cout << "test5" << endl;
}

int main(int *argc, int *argv[]){

	cout << "test1:" << test1 << endl;
	cout << "test2:" << test2 << endl;
	cout << "test3:" << test3 << endl;
	cout << "test4:" << test4 << endl;
	cout << "test5:" << test5 << endl;

	test3();
	test4();

	test2("Hello world!");

	getchar();
	return 0;
}

这里是Debug版本:编译器是MSVC2012:

运行结果如下:

这里看看:从test1到test5:全局函数不像类里面的函数那样,具有规律。这种全局函数看起来是没有什么规律的。

下面来看看Release版本:

这里可以看到使用Realse版本优化后的全局函数地址,是有某种规律的,至少地址是增加的,不像debug那样!

 

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

IT1995

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值