Changes

Jump to: navigation, search

C/C++ FAQ

1,245 bytes added, 00:15, 18 September 2012
Created page with '== C/C++ FAQ == '''Q:''' Why is the postfix increment/decrement operator (e.g. a++ and a--) evaluated differently on different compilers? '''A:''' The evaluation of expressions…'
== C/C++ FAQ ==

'''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>
For example, consider the following snippet:
<source lang="cpp">
#include <iostream>
using namespace std;

#define PI 3.14

int main()
{
double a = 2.35;
cout << PI * ((a++) * (a++))<< endl;
return 0;
}
</source>
The GNU compiler prints 17.3407 as the output whereas the Borland compiler prints 24.7197 as the output.


'''''Submitted by:''''' ''Gideon Thomas and Marie Karimizadeh''
----

Navigation menu