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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:26:45+00:00 2026-05-29T05:26:45+00:00

Possible Duplicate: order of evaluation of function parameters Is it safe to use the

  • 0

Possible Duplicate:
order of evaluation of function parameters

Is it safe to use the following construction in C/C++?

f(g(), h());

where g() is expected to be evaluated first, then h().

Do all compilers show the same behavior on all architectures?

  • 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-29T05:26:46+00:00Added an answer on May 29, 2026 at 5:26 am

    NO! There is no guarantee what order these are carried out in. Only that both g() and h() are carried out before f().
    See this: http://www.gotw.ca/gotw/056.htm
    I think there’s an updated C++11 version of that, I’ll have a look.

    Edit: C++11 version http://herbsutter.com/gotw/_102/

    Edit 2: If you really want to know what specific compilers do, try this: http://www.agner.org/optimize/calling_conventions.pdf
    Section 7 (page 16) may be relevant, though it’s a bit over my head, but for instance __cdecl calling convention means arguments are passed from right to left (at least stored that way), whereas for __fastcall “The first two DWORD or smaller arguments are passed in ECX and EDX registers; all other arguments are passed right to left.” (http://msdn.microsoft.com/en-us/library/6xa169sk%28v=vs.71%29.aspx)

    So it does vary for different compilers.

    Much later edit: It turns out that for constructors using the initializer list syntax (curly braces {}), order of evaluation is guaranteed (even if it is a call to a constructor that does not take a std::initializer_list. See this question.

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

Sidebar

Related Questions

Possible Duplicate: Order of evaluation in C++ function parameters In C++ is the order
Possible Duplicate: C#: Order of function evaluation (vs C) Code snippet: i += ++i;
Possible Duplicate: In what order does evaluation of post-increment operator happen? Consider the following
Possible Duplicate: Python analog of natsort function (sort a list using a “natural order”
Possible Duplicate: Order of execution of parameters guarantees in Java? If I have a
Possible Duplicate: Sorting a hash in Ruby by its value first then its key.
Possible Duplicate: Why i am not getting the expected output in the following c
Possible Duplicate: Unexpected order of evaluation (compiler bug?) I couldn't predict the output for
Possible Duplicate: Compilers and argument order of evaluation in C++ cout << order of
Possible Duplicate: Is short-circuiting boolean operators mandated in C/C++? And evaluation order? AFAIK Short

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.