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) {
The following code has concurrency issues. Here inDegVec is a global int * ,
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.
onItemClickListener has following arguments onItemClick(AdapterView arg0, View arg1,int arg2, long arg3) I am getting
My ASP.NET page has following query string parameter: …?IDs=1000000012,1000000021,1000000013,1000000022&... Here IDs parameter will always
Which of the following has the best performance? I have seen method two implemented
I thought I understood map however the following has results that I don't understand.
In /etc/my.cnf the following has been added character-set-server=utf8 collation-server=utf8_general_ci But for the database and
&mobile=0400000000¬es=this+is+a+test The error is above You will see that the following has occurred ¬es

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.