PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, July 17, 2022

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

 July 17, 2022     c++, warnings     No comments   

Issue

in my c++ code(VS2013) which migration maybe from VC6, there is a warning C4177: #pragma 'float_control' should only be used at global scope or namespace scope for code below:

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

does somebody know how to handle the warning? If I just move these #pragma float_control out of function, and put them in so call global scope. Where should I put? or is there any other solution? thanks,


Solution

The documentation is pretty dire about what will happen if you ignore the warning,

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

So it looks like your only option is to move the pragma outside of the function.

If you don't care about some code here getting included, put the push ahead of the function and the pop after.

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

If you do care about some code here getting included, make another function containing the code currently between the push and pop, surround this new function with push and pop, and call the new function from FunctionNameHere. Something like

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


Answered By - user4581301
Answer Checked By - David Marino (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing