Linux-g++gcc编译后栈内存地址与实际相反

栈正常存储内存地址

image-20220927181002783

栈空间先使用高地址在使用底地址

Win_Devc++

#include <iostream>

using namespace std;

int main() {
	int a = 0;
	int b = 0;
	printf("a == %p\n", &a);
	printf("b == %p\n", &b);
	return 0;
} 
代码_截图

image-20220927155249912

运行_结果
a == 00000000006ffe1c
b == 00000000006ffe18
--------------------------------

Vim(Linux)

#include <iostream>

using namespace std;

int main() {
	int a = 0;
	int b = 0;
	printf("a == %p\n", &a);
	printf("b == %p\n", &b);
	return 0;
} 
运行_结果(默认)

发现二个变量 a, b在栈中存储的地址由高到底分别为 a>b> 跟课上面dev正好相反.

a == 0x7ffffa941740
b == 0x7ffffa941744
关闭栈保护

关闭栈保护后的结果:
与推断的结果相同.

g++ test.cpp  -fno-stack-protector -o ttw
a == 0x7fffc18bfd1c
b == 0x7fffc18bfd18
运行截图

image-20220927181441626

GitHub 加速计划 / li / linux-dash
10.39 K
1.2 K
下载
A beautiful web dashboard for Linux
最近提交(Master分支:23 天前 )
186a802e added ecosystem file for PM2 4 年前
5def40a3 Add host customization support for the NodeJS version 4 年前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐