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

  • Home
  • SEARCH
  • 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 8592817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:50:33+00:00 2026-06-11T23:50:33+00:00

In C++11 is there any defined behaviour regarding the following? (i.e. does a =

  • 0

In C++11 is there any defined behaviour regarding the following? (i.e. does a = 1, 2 or is undefined)

void somefunc(int a, int b) {
  std::cout << a << b << std::endl;
}

int i = 0;
somefunc(++i, ++i)

Or should I write:

int i = 0;
int a = ++i;
int b = ++i;
somefunc(a, b);

The reason I ask, is I’m parsing a file for options and in one circumstance I’d like to create a keyvalue pair. And have functions similar to the following:

std::string create_key(std::string &source, size_t &size, int &index) {
  std:: string key = "";
  while(index < size) {
    // parse the string to create the key
    ++index
  }
  return key;
}

// Value is an base class for a template class. Allowing me to store values 
// of different data types inside a container.
Value* create_value(std::string &source, size_t &size, int &index) {
  Value* value = nullptr;
  while(index < size) {
    // determine type and assign it to value
    ++index;
  }
  return value;
}

std::map<std::string, Value*> create_object(std::string &source, size_t &size, int &index) {
  std::map<std::string, Value*> object;
  while(index < size) {
    // the line I think produces the same issue as my original example
    object.insert(std::pair<std::string, Value*>(create_key(source, size, index), create_value(source, size, index)));
    ++index;
  }
}
  • 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-06-11T23:50:34+00:00Added an answer on June 11, 2026 at 11:50 pm

    Yes, because you are modifying a variable in a manner which is not sequenced with respect to another modification of the same variable. Note that the comma is not a comma operator, which would introduce sequencing and prevent UB; it just separates the function arguments.

    You cannot even do

    somefunc(i, ++i)
    

    without causing undefined behaviour. Modify the variable and then call the function (or vice versa if it’s what you want) separately.

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

Sidebar

Related Questions

Is there any defined behaviour if I have an HTML5 VIDEO tag but include
Is there any method / API defined to collect system info in osx. I
If yes is there any way to access a var defined in another PHP
In a large Application is there any way to distinguish user-defined classes with built-in
WinJS.UI.getControl is not defined in VS 11 Ultimate. Is there any alternatives there to
Is there any explanation of this strange behavior of defined constant? I have 1
I would like to know if there is any way to add custom behaviour
is there any way to define objects in hibernate.cfg.xml by scope and not one
Is there any way to define a variable that can be used in multiple
Is there any mechanism in C# that allows one to define and declare an

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.