C ++编译错误(在此函数中未初始化)[重复]

时间:2021-09-27 03:15:42

This question already has an answer here:

这个问题在这里已有答案:

I need help regarding to this message:

我需要有关此消息的帮助:

cmd_general.cpp:3433: warning: 'safemode' may be used uninitialized in this function

cmd_general.cpp:3433:警告:'safemode'可能在此函数中未初始化使用

Can somone explain what this error means?

可以解释一下这个错误意味着什么吗?

This is the function:

这是功能:

ACMD(do_cards)
{
    const char *line;

    char arg1[256], arg2[256];

    line = two_arguments(argument, arg1, sizeof(arg1), arg2, sizeof(arg2));
    switch (LOWER(arg1[0]))
    {
        case 'o':   // open
            if (isdigit(*arg2))
            {
                DWORD safemode;
                str_to_number(safemode, arg2);
                ch->Cards_open(safemode);
            }
            break;
        default:
            return;
    }
}

1 个解决方案

#1


0  

You are declaring a variable of type DWORD without initializing it:

您正在声明DWORD类型的变量而不初始化它:

DWORD safemode;

Then you are passing it to a function:

然后你将它传递给一个函数:

str_to_number(safemode, arg2);

The compiler does not know that the initial value of the first argument is probably not used by the function, and therefore it is not a real issue here.

编译器不知道函数可能没有使用第一个参数的初始值,因此这不是一个真正的问题。

To resolve the warning, just initialize the variable with a default value:

要解决警告,只需使用默认值初始化变量:

DWORD safemode = 0;

#1


0  

You are declaring a variable of type DWORD without initializing it:

您正在声明DWORD类型的变量而不初始化它:

DWORD safemode;

Then you are passing it to a function:

然后你将它传递给一个函数:

str_to_number(safemode, arg2);

The compiler does not know that the initial value of the first argument is probably not used by the function, and therefore it is not a real issue here.

编译器不知道函数可能没有使用第一个参数的初始值,因此这不是一个真正的问题。

To resolve the warning, just initialize the variable with a default value:

要解决警告,只需使用默认值初始化变量:

DWORD safemode = 0;