Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is a = 0; b = (a++, a + 1) ; undefined behavior (UB)?

see simple example:

int a = 0;
int b = (a ++  ,  a + 1); // result of b is UB or well defined ?  (c++03).

This was changed in c++11/c++14 ?

like image 266
Khurshid Avatar asked Jan 24 '14 07:01

Khurshid


1 Answers

The result is well defined and has been since C++98. The comma operator introduces a sequence point (or a "sequenced before" relationship in later C++s) between the the write and the second read of a and I don't see any other potential reasons for undefined behavior.

like image 195
CB Bailey Avatar answered Oct 21 '22 09:10

CB Bailey