Why function argument evaluation cannot be ordered? [duplicate] - c++

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.

Related

How can I Tell if a Type is a Functor? [duplicate]

This question already has answers here:
Find out whether a C++ object is callable
(8 answers)
Can std::is_invocable be emulated within C++11?
(1 answer)
Closed 3 years ago.
In c++17 I have is_invocable to match function pointers, lambdas, and functors.
But what if I'm trapped on c++14? Do I have a type trait, or can I write one, which will match all of these?
I've tried is_function but that only works on function pointers.
Yes you can, std::is_invocable is a library function which requires no compiler support. You can just rip the implementation from an STL of your choice.
For example, you can find LLVM implementation of __invokable (to which std::is_invocable forwards all the logic in LLVM's STL) here: https://android.googlesource.com/platform/ndk/+/5b3a49bdbd08775d0e6f9727221fe98946f6db44/sources/cxx-stl/llvm-libc++/libcxx/include/type_traits
(I was thinking of extracting it and posting here, but it seems to be too big for a post. On a lighter note, I find difference in spelling - invocable vs invokable - amusing.)

Determine all function calls inlined by g++ [duplicate]

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

Is there any difference between Implementation dependant and undefined behaviour? [duplicate]

This question already has answers here:
Undefined, unspecified and implementation-defined behavior
(9 answers)
Closed 9 years ago.
Is there any difference between Implementation dependant and undefined behaviour as for C/C++ standards?
Implementation dependent means that a certain construct differs from platform to platform but in a defined, well-specified manner. (e.g. the va_arg family of macros in C varies between posix and windows)
Undefined behaviour means that anything (literally) could happen. i.e. totally unspecified. (e.g. the behaviour of i = ++i).

C++ invalid assignment [duplicate]

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

What does the compiler do to perform a cast operation in C++? [duplicate]

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.