我在尝试提交我的作业警告时不断收到此警告:与字符串文字的比较会导致未指定的行为 [-Waddress]
I Keep getting this warning when trying to submit my assignment warning: comparison with string literal results in unspecified behaviour [-Waddress]
真正让我不高兴的是,这适用于 Visual Basic 而不是我糟糕的学校的服务器:(。
注意Mdestination和Mname是指针
if (Mdestination != nullptr && Mname != nullptr && Mname != "" && Mdestination != "") {
strcpy_s(name, Mname);
strcpy_s(destination, Mdestination);
}
}
我相信你在这里混合了指针运算和字符串运算。
Mname != ""
上一行检查指针 Mname 和文字 "" 是否不在同一地址。我相信您的意图是检查 Mname 是否不指向空字符串。在这种情况下,您可以使用
*Mname != '[=11=]' // NUL could also be used instead of '[=11=]'
Mdestination 也一样。
真正让我不高兴的是,这适用于 Visual Basic 而不是我糟糕的学校的服务器:(。
注意Mdestination和Mname是指针
if (Mdestination != nullptr && Mname != nullptr && Mname != "" && Mdestination != "") {
strcpy_s(name, Mname);
strcpy_s(destination, Mdestination);
}
}
我相信你在这里混合了指针运算和字符串运算。
Mname != ""
上一行检查指针 Mname 和文字 "" 是否不在同一地址。我相信您的意图是检查 Mname 是否不指向空字符串。在这种情况下,您可以使用
*Mname != '[=11=]' // NUL could also be used instead of '[=11=]'
Mdestination 也一样。