linux中的g++,如果内容相同,则为MSG
或a指代相同的位置const char *
鉴于:
#include <stdio.h>
#define MSG "Input your last name"
int main()
{
const char* const msgc = "Input your last name";
printf("MACRO %p\n", &MSG);
printf("char %p\n", msgc);
printf("MACRO %p\n", &MSG);
}
以上拆解
(gdb) disassemble main
Dump of assembler code for function main():
0x000000000040070c <+0>: push rbp
0x000000000040070d <+1>: mov rbp,rsp
0x0000000000400710 <+4>: sub rsp,0x10
0x0000000000400714 <+8>: mov QWORD PTR [rbp-0x8],0x400864
0x000000000040071c <+16>: mov esi,0x400864
0x0000000000400721 <+21>: mov edi,0x400879
0x0000000000400726 <+26>: mov eax,0x0
0x000000000040072b <+31>: call 0x4005c0 <printf@plt>
0x0000000000400730 <+36>: mov esi,0x400864
0x0000000000400735 <+41>: mov edi,0x400883
0x000000000040073a <+46>: mov eax,0x0
0x000000000040073f <+51>: call 0x4005c0 <printf@plt>
0x0000000000400744 <+56>: mov esi,0x400864
0x0000000000400749 <+61>: mov edi,0x400879
0x000000000040074e <+66>: mov eax,0x0
0x0000000000400753 <+71>: call 0x4005c0 <printf@plt>
0x0000000000400758 <+76>: mov eax,0x0
0x000000000040075d <+81>: leave
0x000000000040075e <+82>: ret
End of assembler dump.
0x400864
在这种情况下是"Input your last name"
和msgc
和MSG
指向相同的位置。