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 7671605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:05:51+00:00 2026-05-31T16:05:51+00:00

Now I am read the book Inside The C++ Object Model ‘s fourth section

  • 0

Now I am read the book Inside The C++ Object Model ‘s fourth section and have some question.

An inline function like this:

inline int max(int a, int b)
{
    return (a > b) ? a : b;
}

Then, a statement such as the following:
a = max(x, y);

this statement will transformed to a = (x > y) ? x : y;

But the book say when add a local variables to the inline function like this:

inline int max(int a, int b)
{
    int maxval = (a > b) ? a : b;
    return maxval;
}

It will transformed to

int __max_lv_maxval;
a = (__max_lv_maxval = (x > y) ? x : y), __max_lv_maxval;

And obvious the function’s performance will drop.

My question is Does the compile (such as VC2010,gcc) optimize the inline function and delete the local variables?

  • 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-31T16:05:52+00:00Added an answer on May 31, 2026 at 4:05 pm

    That book seems to be assuming the compiler inlines at a source level, this of course totally depends on the compiler. Most will begin inlining at the AST level, where transforms and certain optimizations can and will occur. This all assumes the compiler will inline the code.

    If we look at your function, any decent compiler will turn them both into the same IR code, as it will compile the inline function before it is inlined, thus a temporary is required regardless (at IR level). when the IR is then actually inlined, the temporary will be folded away and instead replaced with the assignment destination of the call to max.

    When we compile down to machine code, things can change even more, not only can temporaries be removed, but the destination will most likely be a register (in this case), which will have probably been used for on of the source operands as well.

    Bottom Line:
    This totally depends on your compiler, optimization levels and how it does variable livelyness analysis, value propagation and folding.

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

Sidebar

Related Questions

I'm new in c#. I have read some book about c# for beginners. Now
I already read this trick in the cookbook: http://book.cakephp.org/2.0/en/models/model-attributes.html#usetable Now I would like to
I read this book: Head First Object-Oriented Analysis and Design Now i am looking
I have a users model and a book model. Users can read books (as
This is surely a stupid question, but I'm stumped. I've now read Odersky's book,
I have done Objective-C way back when, and have recently (i.e. just now) read
Its been a while I have ready Mcconnell's Code Complete . Now I read
From the .net 4.0 previews I have read until now there has been lots
Now that I have a read-only application working, I am working on the insert
I am new to C, and now read some textbook and going to apply

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.