This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Undefined Behavior and Sequence Points
Is there any one know that whether this is valid or not in C++
int a = 0;
a = a++;
Someone told me that it will generate unknown behavior under C++ standard, did anyone know why, and where in the C++ standard states that? Thanks!
I've posted it before, and I will post it again:
http://www.slideshare.net/olvemaudal/deep-c
highly recommended for anybody with such questions in mind
The techincal reason why is that you should not modify the same variable twice (either directly or due to side effects) between sequence points.
Here is an SO question with good answers that clarifies this further and describes sequence points in general.
I don't know about the standard per se (its probably referenced from the C standard anyway), but here you can read about it:
http://www.research.att.com/~bs/bs_faq2.html#evaluation-order
Related
This question already has answers here:
Order of evaluation in C++ function parameters
(6 answers)
Closed 4 years ago.
As far as we know, the function argument evaluation order is not defined by c++ standard.
For example:
f(g(), h());
So we know it is undefined.
My question is, why cant c++ standard define the order of evaluation from left to right??
Because there is no good reason to do so.
The c++ standard generally only defines what is necessary and leaves the rest up to implementers.
This is why it produces fast code and can be compiled for many platforms.
This question already has answers here:
How will i know whether inline function is actually replaced at the place where it is called or not?
(10 answers)
Closed 8 years ago.
I am trying to diagnose a weird performance problem that I think is related to a failure of GCC to inline some function calls in C++, though I am not sure which function calls. Is there a flag to GCC to list all line numbers where inlining was performed?
The answer to your question is here:
C++: How will i know whether inline function is actually replaced?.
The question was slightly different from yours, but the responses are spot-on - and definitely enlightening. I encourage you to read them.
In answer to your question, however:-Winline will generate a warning if the compiler chooses not to inline:
https://gcc.gnu.org/onlinedocs/gcc-4.6.3/gcc/Warning-Options.html
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Does a standard implementation of a Circular List exist for C++?
Is there ready a template class in some c++ library that is some kind of a loop: A liked list where the last node references the first one.
Admittedly this wouldn't always be a practical class to use since there couldn't exist a end() iterator nor a well defined begin() iterator. But I could really have use for one and I was hoping that I wouldn't have to code it myself.
Edit:
Thank you both (Vivek Goel and madmik3) and for your answers, but unfortunately they have nothing to do with my question (I suggest http://en.wikipedia.org/wiki/Linked_list to you both). I also found the same question here, didn't find it yesterday. I apologise for posting the same question.
What about Circular Buffer from boost
http://www.boost.org/doc/libs/1_51_0/libs/circular_buffer/doc/circular_buffer.html
Boost has a circular buffer.
http://www.boost.org/doc/libs/1_51_0/libs/circular_buffer/doc/circular_buffer.html
You can also see sample code here:
http://en.wikipedia.org/wiki/Ring_buffer
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Deprecation of the static keyword… no more ?
I am asking this question because of a comment on an answer of mine which states that the use of static keyword on freestanding (nonmember) functions has been un-deprecated in C++0x.
Since I have no reason to doubt the above statement, I am asking this:
Can anybody please shed light on the underlying rationale of un-deprecating the use of static keyword in that context? (I mean, in C++03 the standard states that anonymous namespaces provide a superior alternative. What's changed?)
Thanks in advance
I found this in the CWG issues list:
http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_closed.html#174
This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
How do C/C++ compilers handle type casting between types with different value ranges?
What does the compiler do to perform a cast operation in C++?
Explain with some sample C++ code.
Standard sections
5.2.7, 5.2.8, 5.2.9, 5.2.10 and 5.2.11
give a good idea on how these casts work (which is what compiler and/or runtime implement).
reinterpret_cast is the only one whose behavior is kind of implementation defined.