Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6738991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:26:04+00:00 2026-05-26T11:26:04+00:00

There is such code: int fun1(){ return 2 + 3; } inline int fun2(){

  • 0

There is such code:

int fun1(){
   return 2 + 3;
}

inline int fun2(){  
   return 4 + 5;
}

int main(){
    int a = fun1();
    int b = fun2();
    return 0;
}

and corresponding assembly code:

    .file   "prog47.cpp"
    .text
.globl _Z4fun1v
    .type   _Z4fun1v, @function
_Z4fun1v:
.LFB0:
    .cfi_startproc
    .cfi_personality 0x0,__gxx_personality_v0
    pushl   %ebp
    .cfi_def_cfa_offset 8
    movl    %esp, %ebp
    .cfi_offset 5, -8
    .cfi_def_cfa_register 5
    movl    $5, %eax
    popl    %ebp
    ret
    .cfi_endproc
.LFE0:
    .size   _Z4fun1v, .-_Z4fun1v
    .section    .text._Z4fun2v,"axG",@progbits,_Z4fun2v,comdat
    .weak   _Z4fun2v
    .type   _Z4fun2v, @function
_Z4fun2v:
.LFB1:
    .cfi_startproc
    .cfi_personality 0x0,__gxx_personality_v0
    pushl   %ebp
    .cfi_def_cfa_offset 8
    movl    %esp, %ebp
    .cfi_offset 5, -8
    .cfi_def_cfa_register 5
    movl    $9, %eax
    popl    %ebp
    ret
    .cfi_endproc
.LFE1:
    .size   _Z4fun2v, .-_Z4fun2v
    .text
.globl main
    .type   main, @function
main:
.LFB2:
    .cfi_startproc
    .cfi_personality 0x0,__gxx_personality_v0
    pushl   %ebp
    .cfi_def_cfa_offset 8
    movl    %esp, %ebp
    .cfi_offset 5, -8
    .cfi_def_cfa_register 5
    andl    $-16, %esp
    subl    $16, %esp
    call    _Z4fun1v
    movl    %eax, 12(%esp)
    call    _Z4fun2v        # why fun2 is called?
    movl    %eax, 8(%esp)
    movl    $0, %eax
    leave
    ret
    .cfi_endproc
.LFE2:
    .size   main, .-main
    .section    .note.GNU-stack,"",@progbits

Why function fun2 is not inlined and called like normal function? I have read that inline keyword is only hint for compiler and it doesn’t have to inline function, however definition of fun2 is so simple, so it could be inlined. How to force g++ to inline functions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T11:26:05+00:00Added an answer on May 26, 2026 at 11:26 am

    GCC has an attribute which forces inlining: always_inline

    inline int fun2()  __attribute__((always_inline));
    inline int fun2() {  
       return 4 + 5;
    }
    

    Will cause it to work on any optimization settings.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There is such code: const int fun(){ return 2; } // can be assigned
There is such code: #include <iostream> int main() { int size; std::cin >> size;
There is such code: #include <iostream> int main() { int a; int* p =
There is such code: #include <iostream> int main(){ unsigned int* wsk2 = new unsigned
There is such code: #include <iostream> int main(){ const int a = 2; int*
There is such code: #include <iostream> #include <string> int returnnumber() { return 2; }
There is such code: int (*ptr_)[1] = new int[1][1]; ptr_[0][0] = 100; std::cout <<
There is such code: #include <iostream> class A{ int a; int fun(){} }; class
There is such code: #include <iostream> class A { public: int a; A() :
In a JSP page, there is such code: <jsp:useBean id=checklog class=com.google.admin.guard.CheckLogBean scope=session /> and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.