【问题标题】:VSCode is throwing 'identifier "M_PI" is undefined' [duplicate]VSCode抛出'标识符“M_PI”未定义'[重复]
【发布时间】:2021-10-28 02:30:59
【问题描述】:

我有以下代码:

#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);
}

我可以用 gcc 很好地运行它:

$&gt; gcc -Wall -Werror -Wextra -o SphereVolume SphereVolume.c -lm

但是 VS Code 甚至不允许我调试代码。怎么了?我是不是搞砸了设置?

【问题讨论】:

  • “连调试代码都不让我” 这和你得到的宏相关的错误无关,但是不知道细节很难说别的。
  • M_PI 不是标准宏。毫不奇怪,这里缺少它,因为代码没有定义它。

标签: c visual-studio-code vscode-extensions vscode-debugger


【解决方案1】:

我想我找到了答案:

M_PI not available with gcc --std=c11 but with --std=gnu11?

显然 M_PI 没有在标准 C 中定义

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-21
    • 2015-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多