如何处理警告 C4177:#pragma 'float_control' 只应在全局范围或命名空间范围内使用

how to handle warning C4177: #pragma 'float_control' should only be used at global scope or namespace scope

在我的可能从 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.

看来您唯一的选择就是将编译指示移到函数之外。

如果您不关心 some code here 是否包含在内,请将 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)

如果您确实关心 some code here 是否包含在内,请创建另一个包含当前 push 和 pop 之间代码的函数,用 push 和 pop 包围这个新函数,然后从 [=14= 调用新函数].像

#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);
}