About inline

xiaoxiao2021-04-08  404

Is the member function defined in the class definition be automatically as an inline function? Or explicitly add Inline keywords when defining member functions, which will be defined into inline? Actually not! For compilers, the inline function is a request, not a guarantee (C Primer (3ed) P26). The following is taken as an example of code generated under VC 7.0. // Inline inline function demonstration // inlinedemo.h

#pragma overce

#include

Using namespace std;

Class inline {public: // inline? Inline () {cout << "inline construct!" << endl;

// inline? Void setab (int A, int b) {this-> a = a; this-> b = b;} int GETA (); int Getb (); protected: int A, b;};

// inline? inline int inline :: geta () {return a;}

// Non-inline? int inline :: getb () {return b;}

// inlineDemo.cpp: Define the entry point of the console application. //

#include "stdafx.h" #include "inlineDemo.h"

INT _TMAIN (int Argc, _tchar * argv []) {inline inlinea;

Inlinea.seTab (10, 12);

COUT << inlinea.geta () << endl;

Cout << inlinea.getb () << endl;

Return 0;}

Option / 0B1 ("Online Function Expand" only suitable for __inline ") open anti-assessment code: .text: 004012d0 _main proc near; code xref: j__mainj.text: 004012d0.text: 004012d0 var_58 = DWORD PTR -58h.text: 004012D0 var_40 = dword ptr -40h.text: 004012D0 var_28 = dword ptr -28h.text: 004012D0 var_C = dword ptr -0Ch.text: 004012D0 var_8 = dword ptr -8.text: 004012D0.text: 004012D0 push ebp.text: 004012D1 mov ebp, esp.text: 004012D3 sub esp, 58h.text: 004012D6 push edi.text: 004012D7 lea edi, [ebp var_58] .text: 004012DA mov ecx, 16h.text: 004012DF mov eax , 0CCCCCCCCh.text: 004012E4 rep stosd.text: 004012E6 push offset ?? _ C @ _0BC @ FJCDLOJM @ inLine 5Construct $ CB $ AA @; "inLine Construct!" is compiled into .text inline:??? 004012EB push offset STD__cout.text: 004012f0 Call J _? $? 6u? $ char_traits @ d @STD @@@st D @@ yaAAV? $ BASIC_OSTREAM @ du? $ char_traits @ D @ std @@@ 0 @ aav10 @ Pbd @ z.text: 004012f5 add esp, 8.Text: 004012F8 MOV [EBP VAR_28], EAX.TEXT: 004012FB Push 0ah.text: 004012FD MOV ECX, [EBP VAR_28] .TEXT: 00401300 CALL J_ PUT @? $ basic_ostream @ du? $ char_traits @@ @@ qaeaav12 @ D @ z; std :: Basic_OStream > :: put (char) .text: 00401305 MOV ECX, [EBP VAR_28] .TEXT: 00401308 CALL J_? Flush @? $ Basic_OStream @

DU? $ Char_traits @@ @@@ std @@ qaeaav12 @ xz; std :: basic_ostream > :: flush (void), self-this constructor output "Inline Construct!" Complete .Text: 0040130D MOV [EBP VAR_C], 0AH; Inline :: setab (10, 12) Start .Text: 00401314 MOV [EBP VAR_8], 0CH; Inline :: setab (10, 12) end .Text: 0040131B MOV EAX, [EBP VAR_C] .Text: 0040131E Push Eax.Text: 0040131F MOV ECX, Offset STD__cout.text: 00401324 Call J _ ?? 6? $ Basic_ostream @ du? $ Char_traits @ d @STD @@@ std @@@ std @@@ std @@@ std @@@ std @@@ std @@@ std @@@ std @@@ std @@@ std @@@ std @@@ std @@@ std @@@ @ Qaeaav01 @ h @ z; std :: basic_ostream > :: operator << (int) .text: 00401329 MOV [EBP VAR_40], EAX; inline:: Geta () Expand .Text: 0040132c Push 0ah.text: 0040132E MOV ECX, [EBP VAR_40] .text: 00401331 Call J_? Put @? $ Basic_ostream @ du? $ Char_traits @@ @@@ @@ qaeaav12 @ d @ Z; std :: basic_ostream > :: put (char) .text: 00401336 MOV ECX, [EBP VAR_40] .text: 00401339 Call J_? Flush @? $ Basic_OStream @ du? $ char_traits @@ @@@ @@ qaeaav12 @ xz; std :: basic_ostream > :: flush (void) .Text: 0040133E Lea ECX, [EBP VAR_C] .TEXT: 00401341 CALL J_? Getb @ inline @@ qaehxz;

Inline :: getB (void) is non-inline .Text: 00401346 push eax.text: 00401347 MOV ECX, OFFSET STD__COUT.TEXT: 0040134C Call J _ ?? 6? $ Basic_ostream @ du? $ Char_traits @ d @ std @@@@ STD @@ qaeaav01 @ h @ z; std :: basic_ostream > :: operator << (int) .text: 00401351 mov [EBP VAR_58], EAX.TEXT: 00401354 PUSH 0AH .text: 00401356 MOV ECX, [EBP VAR_58] .TEXT: 00401359 CALL J_? PUT @? $ Basic_OStream @ du? $ char_traits @@ @@ qaeaav12 @ D @ z; std :: Basic_OStream < Char, std :: char_traits > :: put (char) .text: 0040135E MOV ECX, [EBP VAR_58] .TEXT: 00401361 CALL J_? Flush @? $ basic_ostream @ du? $ char_traits @ d @ std @ @@ std @@ @@ qaeaav12 @ xz; std :: basic_ostream > :: flush (void) .text: 00401366 xor Eax, Eax.Text: 00401368 Push Edx.Text: 00401369 MOV ECX , ebp.text: 0040136B push eax.text: 0040136C lea edx, dword_401388.text: 00401372 call _RTC_CheckStackVars.text: 00401377 pop eax.text: 00401378 pop edx.text: 00401379 pop edi.text: 0040137A add esp, 58h.text: 0040137D cmp ebp, esp .text: 0040137f call _rtc_checkesp.text: 00401384 MOV ESP, EBP.TEXT: 00401386 POP EBP.TEXT: 00401387 RETN.TEXT: 00401387 _MAIN ENDP in this case,

The answer to the two questions is affirmative. This option has not been opened as an anti-disassembly code: .text: 004015d0 _Main proc near; code xref: j__mainj.text: 004015d0.text: 004015d0 var_10 = DWORD PTR-10H.TEXT: 004015D0 var_c = dword PTR-0CH.TEXT: 004015D0 var_8 = dword ptr -8.text: 004015D0 var_4 = dword ptr -4.text: 004015D0.text: 004015D0 push ebp.text: 004015D1 mov ebp, esp.text: 004015D3 sub esp, 10h.text: 004015D6 mov eax, 0cccccccch.text: 004015dB MOV [EBP VAR_10], EAX.TEXT: 004015DE MOV [EBP VAR_C], EAX.TEXT: 004015E1 MOV [EBP VAR_8], EAX.TEXT: 004015E4 MOV [EBP VAR_4], EAX. Text: 004015E7 LEA ECX, [EBP VAR_C] .text: 004015EA CALL J _ ?? 0inline @@ qe @ xz; inline :: inline (void) .text: 004015ef push 0ch.text: 004015f1 push 0ah.text: 004015F3 LEA ECX, [EBP VAR_C] .TEXT: 00401 5F6 Call J_? Setab @ inline @@ qaexhh @ z; inline :: setab (int, int) .text: 004015fb push offset LOC_4010B4.TEXT: 00401600 LEA ECX, [EBP VAR_C] .TEXT: 00401603 CALL J_? Geta @ Inline @@ Qaehxz; Inline :: Geta (void) .text: 00401608 Push Eax.Text: 00401609 MOV ECX, Offset std__cout.text: 0040160E Call J _ ?? 6? $ Basic_ostream @ du? $ Char_traits @ d @ std @@ @ std @@ qEaav01 @ h @ z; std :: basic_ostream > :: operator <<

(int) .text: 00401613 MOV ECX, Eax.Text: 00401615 Call J _ ?? 6? $ basic_ostream @ du? $ char_traits @@ @@ qaeaav01 @@ z @ z; std :: Basic_OStream > :: operator << (std :: basic_ostream > & (*) (std :: basic_ostream > &)). Text: 0040161A Push Offset LOC_4010B4.TEXT: 0040161F LEA ECX, [EBP VAR_C] .TEXT: 00401622 CALL J_? getB @ inline @@ Qaehxz; Inline :: getB (void) .text : 00401627 push eax.text: 00401628 mov ecx, offset std__cout.text: 0040162D call j _ ?? 6 $ basic_ostream @ DU $ char_traits @ D @ std @@@ std @@ QAEAAV01 @ H @ Z; std :: basic_ostream?? > :: operator << (int) .text: 00401632 MOV ECX, EAX.TEXT: 00401634 CALL J _ ?? 6? $ basic_ostream @ du? $ char_traits @ d @ std @@ @STD @@ qaeaav01 @ p6aaav01 @ aav01 @@ z @ z; std :: basic_ostream > :: operator << (st: Basic_ostream > & (std :: basic_ostream >)

转载请注明原文地址:https://www.9cbs.com/read-132660.html

New Post(0)