gpt4 book ai didi

c++ - 杂注警告(禁用 : 4700 ) not working in Visual Studio Express 2013

转载 作者:太空狗 更新时间:2023-10-29 21:38:02 24 4
gpt4 key购买 nike

在禁用 SDL 检查的情况下在发布配置中编译以下代码:

#include <immintrin.h>

int main()
{
const auto Set128Epi16 = []()
{
#ifdef NDEBUG
#pragma warning( push )
#pragma warning( disable : 4700 )
__m128i x = _mm_cmpeq_epi16( x,x );
x = _mm_srli_epi16( x,15 );
return _mm_slli_epi16( x,7 );
#pragma warning( pop )
#else
__m128i x = _mm_setzero_si128();
x = _mm_cmpeq_epi16( x,x );
x = _mm_srli_epi16( x,15 );
return _mm_slli_epi16( x,7 );
#endif
};

const auto xmm = Set128Epi16();

return *xmm.m128i_i32;
}

给出以下输出:

1>------ Rebuild All started: Project: pragmatic, Configuration: Release Win32 ------
1> main.cpp
1> Generating code
1>e:\projects\pragmatic\pragmatic\main.cpp(10): warning C4700: uninitialized local variable 'x' used
1>e:\projects\pragmatic\pragmatic\main.cpp(10): warning C4700: uninitialized local variable 'x' used
1>e:\projects\pragmatic\pragmatic\main.cpp(10): warning C4700: uninitialized local variable 'x' used
1>e:\projects\pragmatic\pragmatic\main.cpp(10): warning C4700: uninitialized local variable 'x' used
1>e:\projects\pragmatic\pragmatic\main.cpp(10): warning C4700: uninitialized local variable 'x' used
1> Finished generating code
1> pragmatic.vcxproj -> E:\Projects\pragmatic\Release\pragmatic.exe
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========

在这种情况下,为什么编译器会忽略我的#pragma。我过去曾成功地使用这种方法来抑制相同的警告代码。

最佳答案

我从 https://msdn.microsoft.com/en-us/library/2c8f766e.aspx 复制了这个

For warning numbers in the range 4700-4999, which are the ones associated with code generation, the state of the warning in effect when the compiler encounters the open curly brace of a function will be in effect for the rest of the function. Using the warning pragma in the function to change the state of a warning that has a number larger than 4699 will only take effect after the end of the function. The following example shows the correct placement of warning pragmas to disable a code-generation warning message, and then to restore it.

因此您可能需要在 main 开始之前放置 pragma,或者可能在 lambda 起作用之前,但我不确定。

关于c++ - 杂注警告(禁用 : 4700 ) not working in Visual Studio Express 2013,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36262702/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com