Open main menu

CDOT Wiki β

Changes

C/C++ FAQ

720 bytes added, 20:11, 25 October 2012
no edit summary
== C/C++ FAQ ==
<pre>
Q: Why is the postfix increment/decrement operator (e.g. a++ and a--) evaluated
differently on different compilers?
Q: Why is the postfix increment/decrement operator (e.g. a++ and a--) evaluated
differently on different compilers?
Q: When we define a function-like macro, does the compiler ignore or take into
consideration the spaces in between the parentheses?
Q: When using square-bracket pointer arithmetic, does ptr[-k] decrement the pointer?
Q: Is this syntax for pointer casting and dereferencing *(int*)p for void* p equivalent
to (*(int*)p)?
Q: Why can't void* variables be dereferenced?
Q: Can a functional pointer be used to point to an overloaded function? If so, which
function will it call when the pointer is dereferenced and why?
Q: How to redirect cerr to a file (instead of a console window)?
</pre>
'''Q:''' Why is the postfix increment/decrement operator (e.g. a++ and a--) evaluated differently on different compilers?
'''A:''' The evaluation of expressions, especially arithmetic expressions are based on sequence points which are undefined by the language. Arithmetic expressions containing complex postfix calculations are evaluated differently across different compilers because each compiler is unequally efficient. That is to say, these expressions are not portable as each compiler uses a different way to evaluate the expression based on its efficiency implementation. This can be noted by observing the process time of an expression across different platforms, which will be different for the same expression, due to different methods of evaluation. <br>
1
edit