在这段代码中,我连续多次访问 exitButton.rectangle,我想知道它是否经过优化,因此生成的目标代码不必每次都exitButton
要求:rectangle
struct MenuItem {
Rectangle rectangle;
};
MenuItem exitButton;
exitButton.rectangle.top = 383;
exitButton.rectangle.height = 178;
exitButton.rectangle.left = 0;
exitButton.rectangle.width = 1024;
我需要写这样的东西来保证它是优化的吗?
Rectangle &tempRectangle = exitButton.rectangle;
tempRectangle.top = 383;
tempRectangle.height = 178;
tempRectangle.left = 0;
tempRectangle.width = 1024;
它会是一样的,但使用一个类而不是一个结构吗?提前致谢。
编辑
g++ -o0,无参考:
CPU Disasm
Address Hex dump Command Comments
004013B0 /$ 55 PUSH EBP ; CppTest.004013B0(guessed void)
004013B1 |. 89E5 MOV EBP,ESP
004013B3 |. 83E4 F0 AND ESP,FFFFFFF0 ; DQWORD (16.-byte) stack alignment
004013B6 |. 83EC 10 SUB ESP,10
004013B9 |. E8 42060000 CALL 00401A00 ; [CppTest.00401A00
004013BE |. C70424 7F0100 MOV DWORD PTR SS:[LOCAL.4],17F
004013C5 |. C74424 04 B20 MOV DWORD PTR SS:[LOCAL.3],0B2
004013CD |. C74424 08 000 MOV DWORD PTR SS:[LOCAL.2],0
004013D5 |. C74424 0C 000 MOV DWORD PTR SS:[LOCAL.1],400
004013DD |. B8 00000000 MOV EAX,0
004013E2 |. C9 LEAVE
004013E3 \. C3 RETN
g++ -o0,参考:
CPU Disasm
Address Hex dump Command Comments
004013B0 /$ 55 PUSH EBP ; CppTest.004013B0(guessed void)
004013B1 |. 89E5 MOV EBP,ESP
004013B3 |. 83E4 F0 AND ESP,FFFFFFF0 ; DQWORD (16.-byte) stack alignment
004013B6 |. 83EC 20 SUB ESP,20
004013B9 |. E8 62060000 CALL 00401A20 ; [CppTest.00401A20
004013BE |. 8D4424 0C LEA EAX,[LOCAL.5]
004013C2 |. 894424 1C MOV DWORD PTR SS:[LOCAL.1],EAX
004013C6 |. 8B4424 1C MOV EAX,DWORD PTR SS:[LOCAL.1]
004013CA |. C700 7F010000 MOV DWORD PTR DS:[EAX],17F
004013D0 |. 8B4424 1C MOV EAX,DWORD PTR SS:[LOCAL.1]
004013D4 |. C740 04 B2000 MOV DWORD PTR DS:[EAX+4],0B2
004013DB |. 8B4424 1C MOV EAX,DWORD PTR SS:[LOCAL.1]
004013DF |. C740 08 00000 MOV DWORD PTR DS:[EAX+8],0
004013E6 |. 8B4424 1C MOV EAX,DWORD PTR SS:[LOCAL.1]
004013EA |. C740 0C 00040 MOV DWORD PTR DS:[EAX+0C],400
004013F1 |. B8 00000000 MOV EAX,0
004013F6 |. C9 LEAVE
004013F7 \. C3 RETN