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

时间:2022-06-07 00:41:34

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 :

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

  • using %option yylineno

    使用%选项yylineno

  • or -l option

    或- l选项

I have always this kind of warning :

我一直有这样的警告:

warning C4102: 'find_rule' : unreferenced label

警告C4102: 'find_rule':未引用标签

any help please to avoid this warning!

任何帮助请避免这个警告!

2 个解决方案

#1


1  

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:

选项2是将.c文件包含到另一个文件中,并将其封装到#pragma警告中:

//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.

而且(重要的是!)要么不将有问题的.c文件包含到项目中,要么将原始的.c文件从build中排除(“从build中排除”属性),这样它就不会被编译和链接两次。

#2


1  

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

根据C4102的描述,原因是一个未引用的标签:

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.

或者指定/wd4102作为编译器切换。

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).

当您声明这是生成的代码时,您不希望更改编译器切换是惟一的选项(我可以考虑)。

#1


1  

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:

选项2是将.c文件包含到另一个文件中,并将其封装到#pragma警告中:

//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.

而且(重要的是!)要么不将有问题的.c文件包含到项目中,要么将原始的.c文件从build中排除(“从build中排除”属性),这样它就不会被编译和链接两次。

#2


1  

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

根据C4102的描述,原因是一个未引用的标签:

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.

或者指定/wd4102作为编译器切换。

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).

当您声明这是生成的代码时,您不希望更改编译器切换是惟一的选项(我可以考虑)。