避免警告:未引用的 find_rule 标签

发布于 2024-12-26 03:38:03 字数 300 浏览 4 评论 0原文

为了让 flex 和其他版本的 lex 之间有更多的兼容性,我们应该在 flex 命令中添加 -l 选项。 这些不兼容性之一是 yylineno(用于存储行号的全局变量)。虽然有两种方法可以激活此选项:

  • using %option yylineno

  • 或 -l 选项

我总是收到此类警告:

警告 C4102:“find_rule”:未引用标签

请帮助避免此警告!

In order To get more compatibility between flex and other version of lex , we should add -l option in flex command.
One of these incompatibilities is yylineno (global variable to store line number). Although there are two ways to activate this option :

  • using %option yylineno

  • or -l option

I have always this kind of warning :

warning C4102: 'find_rule' : unreferenced label

any help please to avoid this warning!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

酷炫老祖宗 2025-01-02 03:38:03

既然您说触发警告的代码是自动生成的并且无法由您控制,那么消除警告的唯一方法就是仅针对该代码抑制它。你有两个选择。

选项一是更改特定文件的编译器设置(不是最好的维护方式)。

选项 2 是将 .c 文件#include 到另一个文件中,并将其包装到 #pragma warning 中:

//WrapperGateFile.c
#pragma warning(push)
#pragma warning(disable: 4102)

#include "ProblematicFile.c"

#pragma warning(pop)

并且(重要!)要么不将有问题的 .c 文件包含到项目或从构建中排除原始 .c 文件(“从构建中排除”属性),以便它不会被编译和链接两次。

Since you say that the code triggering the warning is auto-generated and can't be controlled by you, the only way to get rid of the warning is to suppress it for that code only. You have two options.

Option one is to alter the compiler settings for the specific file (not the best thing to maintain).

Option 2 is to #include the .c file into another file and wrap that into #pragma warning:

//WrapperGateFile.c
#pragma warning(push)
#pragma warning(disable: 4102)

#include "ProblematicFile.c"

#pragma warning(pop)

and (important!) either not include the problematic .c file into the project or exclude the original .c file from build ("Excluded from build" property) so that it is not compiled and linked twice.

可遇━不可求 2025-01-02 03:38:03

根据 C4102 的描述Cause 是未引用的标签:

int f()
{
    test: // This will produce C4102

    return 1;
}

int main()
{
    f();
    return 0;
}

要防止出现警告,您可以删除未使用的标签或通过修改源:

#pragma warning(push)
#pragma warning(disable: 4102)
void f()
{
    test: // This will produce C4102

    return;
}
#pragma warning(pop)

或指定 /wd4102 作为编译器开关来禁用警告。

正如您所说,这是生成的代码,您不希望更改编译器开关是唯一的选择(我能想到)。

Based on the description from C4102 the cause is an unreferenced label:

int f()
{
    test: // This will produce C4102

    return 1;
}

int main()
{
    f();
    return 0;
}

To prevent the warning you can remove the unused label or disable the warning by either modifying the source:

#pragma warning(push)
#pragma warning(disable: 4102)
void f()
{
    test: // This will produce C4102

    return;
}
#pragma warning(pop)

or by specifying /wd4102 as a compiler switch.

As you state this is generated code which you do not wish to change the compiler switch is the only option (I can think of).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文