Linux-g++gcc编译后栈内存地址与实际相反
栈正常存储内存地址
栈空间先使用
高地址
在使用底地址
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;
}
代码_截图
运行_结果
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