3.18. C++
Next
Prev
X=garbage
Y=garbage
Next
Prev
X=1st ele-
ment
Y=1st ele-
ment
Next
Prev
X=2nd ele-
ment
Y=2nd ele-
ment
Next
Prev
X=3rd ele-
ment
Y=3rd ele-
ment
Variable
std::list
list.end() list.begin()
GCC has its dummy element at the end of the list, while MSVC’s is at the beginning.
Listing 3.111: Optimizing MSVC 2012 /Fa2.asm /GS- /Ob1
_l$ = -16 ; size = 8
_t1$ = -8 ; size = 8
_main PROC
sub esp, 16
push ebx
push esi
push edi
push 0
push 0
lea ecx, DWORD PTR _l$[esp+36]
mov DWORD PTR _l$[esp+40], 0
; allocate firstgarbage element
call ?_Buynode0@?$_List_alloc@$0A@U?$_List_base_types@Ua@@V?⤦
Ç$allocator@Ua@@@std@@@std@@@std@@QAEPAU?$_List_node@Ua@@PAX@2@PAU32@0@Z ; std::⤦
Ç_List_alloc<0,std::_List_base_types<a,std::allocator > >::_Buynode0
mov edi, DWORD PTR impprintf
mov ebx, eax
push OFFSET $SG40685 ; '* empty list:'
mov DWORD PTR _l$[esp+32], ebx
call edi ; printf
lea eax, DWORD PTR _l$[esp+32]
push eax
call ?dump_List_val@@YAXPAI@Z ; dump_List_val
mov esi, DWORD PTR [ebx]
add esp, 8
lea eax, DWORD PTR _t1$[esp+28]
push eax
push DWORD PTR [esi+4]
lea ecx, DWORD PTR _l$[esp+36]
push esi
mov DWORD PTR _t1$[esp+40], 1 ; data for a new node
mov DWORD PTR _t1$[esp+44], 2 ; data for a new node
; allocate new node
call ??$_Buynode@ABUa@@@?$_List_buy@Ua@@V?$allocator@Ua@@@std@@@std@@QAEPAU?⤦
Ç$_List_node@Ua@@PAX@1@PAU21@0ABUa@@@Z ; std::_List_buy<a,std::allocator >::_Buynode<a ⤦
Çconst &>
mov DWORD PTR [esi+4], eax
mov ecx, DWORD PTR [eax+4]
mov DWORD PTR _t1$[esp+28], 3 ; data for a new node
mov DWORD PTR [ecx], eax
mov esi, DWORD PTR [ebx]
lea eax, DWORD PTR _t1$[esp+28]
push eax
push DWORD PTR [esi+4]
lea ecx, DWORD PTR _l$[esp+36]
push esi
mov DWORD PTR _t1$[esp+44], 4 ; data for a new node