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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:15:36+00:00 2026-05-27T20:15:36+00:00

The following has unspecified results because evaluation order is unspecified: std::string f() { std::cout

  • 0

The following has unspecified results because evaluation order is unspecified:

std::string f() {
   std::cout << "f()";
   return "";
}

std::string g() {
   std::cout << "g()";
   return "";
}

int main() {
   std::cout << f() << g();
}

// Output: "f()g()" or "g()f()".

To the best of my knowledge, though, it’s not invoking undefined behaviour.

However, modifying a variable twice between sequence points is definitely UB, e.g.:

int main() {
   int x = 0;
   std::cout << x++ << x++;
}

Now, does that rule refer only to the current scope, or would the following also be UB?

int foo() {
   static int x = 0;
   x++;
   return x;
}

int main() {
   std::cout << foo() << foo();
}

// Output: "12" or "21", or is it undefined?

The reason I ask is that my GCC 4.7.0 20111217 doesn’t warn on snippet 3, but (of course) will on snippet 2.

  • 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-27T20:15:37+00:00Added an answer on May 27, 2026 at 8:15 pm

    Both calling a function and returning from a function are sequence
    points, so nothing you do in one function can conflict with what you do
    in another (even if the order in which the functions are called is
    unspecified).

    Note that in this regard, user defined operator overloads are functions,
    and introduce sequence points that wouldn’t be present for built in
    types. So that something like cout << i++ << i++ isn’t undefined
    behavior if i is a user defined type (e.g. an enum with a user defined
    operator++). (The order is still unspecified, however, and just
    because the behavior is defined doesn’t mean that the code is readable
    or recommendable.)

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

Sidebar

Related Questions

The following code has a memoryleak. class Program { static void Main(string[] args) {
Which of the following has the best performance? I have seen method two implemented
I've one interface which has following method signatures: public interface ITag { int M_Id
I need to parse out the string that has following structure x:{a,b,c,}, y:{d,e,f} etc.
My ASP.NET page has following query string parameter: …?IDs=1000000012,1000000021,1000000013,1000000022&... Here IDs parameter will always
I just wonder what usage the following code has: public class Sub extends java.util.ArrayList<String>
I have a UserBll class which has following method public string GetaspnetUserIdByUserName(string name )
I thought I understood map however the following has results that I don't understand.
The following code has a simple binding which binds the Text of the TextBlock
i have a table that has following column Type -------- type 1 type 2

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.