I have the following code:
#define _USE_MATH_DEFINES
#include <math.h>
#include <stdio.h>
char r[15];
double radius;
double SphereVolume(double radius){
double volume;
volume = (4.0 / 3.0) * (M_PI) * (pow(radius, 3.0)); ///'identifier "M_PI" is undefined'
return (volume);
}
int main()
{
/* gets input from the user */
printf("What is the radius of the Sphere? ");
fgets(r, sizeof(r), stdin);
sscanf(r, "%lf", &radius);
printf("Volume of the sphere is %f", SphereVolume(radius));
return (0);
}
I can run it well with gcc by doing:
$> gcc -Wall -Werror -Wextra -o SphereVolume SphereVolume.c -lm
But VS Code isn't letting me even debugging the code. What is happening? do I have messed up settings?
I think I found the answer:
M_PI not available with gcc --std=c11 but with --std=gnu11?
Apparently M_PI is not defined in standard C