gpt4 book ai didi

c++ - 如何处理警告 C4177 : #pragma 'float_control' should only be used at global scope or namespace scope

转载 作者:行者123 更新时间:2023-11-30 03:25:39 24 4
gpt4 key购买 nike

在我的可能从 VC6 迁移的 C++ 代码(VS2013)中,有一个警告 C4177: #pragma 'float_control' should only be used at global scope or namespace scope对于下面的代码:

    bool ClassNameHere::FunctionNameHere(Process::FileInfo *fileInfo, RBF &File, PaveConfig &cfg)
{
//some code here

#pragma float_control( strict, on, push )

// Calculate sample interval.
double dResolution = 1000000 / odo.dOdoFactor; // (1.0 / odo.dOdoFactor) * 1000000.0;

double dPulsesPerElevInterval = (DWORD)cfg.fSampleInterval / dResolution;
// Small fix for test mode surveys
if (odo.dOdoFactor != 1)
dPulsesPerElevInterval = DWORD(1.0 + dPulsesPerElevInterval);

//some code here
//....
//...
dElevInterval = dElevInterval / 1000.0;
dAccelInterval = dAccelInterval / 1000.0;
#pragma float_control(pop)
return true;
}

有人知道如何处理警告吗?如果我只是将这些#pragma float_control 移出功能,并将它们放在所谓的全局范围内。我应该放在哪里?或者还有其他解决方案吗?谢谢,

最佳答案

The documentation如果您忽略警告,将会发生什么,这是非常可怕的,

The pragma will not be valid until global scope is encountered after the current scope.

所以看起来您唯一的选择是将 pragma 移到函数之外。

如果您不关心是否包含这里的某些代码,请将 push 放在函数之前,将 pop 放在函数之后。

#pragma float_control( strict, on, push )
bool ClassNameHere::FunctionNameHere(Process::FileInfo *fileInfo, RBF &File, PaveConfig &cfg)
{
//some code here
// code we care about here
}
#pragma float_control(pop)

如果您确实关心包含这里的一些代码,请创建另一个包含当前在 push 和 pop 之间的代码的函数,用 push 和 pop 包围这个新函数,然后从 函数名在这里。有点像

#pragma float_control( strict, on, push )
bool ClassNameHere::HelperForFunctionNameHere (Process::FileInfo *fileInfo, RBF &File, PaveConfig &cfg)
{
// code we care about here
}
#pragma float_control(pop)

bool ClassNameHere::FunctionNameHere(Process::FileInfo *fileInfo, RBF &File, PaveConfig &cfg)
{
//some code here
return HelperForFunctionNameHere(fileInfo, File);
}

关于c++ - 如何处理警告 C4177 : #pragma 'float_control' should only be used at global scope or namespace scope,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48896276/

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