Frage

I have defined a constant as follows

 #define M_PI 3.14159265358979323846;

And I cannot use it as an argument in the pow-function

 double d = pow(M_PI * 2, 0.5);

That is - the squareroot of M_PI * 2

I get a cryptic syntax-error in eclipse

What is wrong with this code? Have no problem using the constant outside the function

War es hilfreich?

Lösung

Remove the trailing semicolon from this line:

#define M_PI 3.14159265358979323846;

to have it look like this:

#define M_PI 3.14159265358979323846

Macros are expanded by the pre-processor before compilation, so the code passed to the compiler using your version would look like:

double d = pow(3.14159265358979323846; * 2, 0.5);
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top