Code Monkey home page Code Monkey logo

Comments (5)

madmann91 avatar madmann91 commented on May 23, 2024

The C++ standard states: Any pragma that is not recognized is ignored.
This means that this code is fine. I don't have MSVC, nor do I plan on paying any Windows license to use that broken and poorly designed piece of software (there are other arguments to defend that position, namely that even on Windows, you have better options both in terms of standard compliance and performance of the generated code -- e.g. clang). I test that it works on Windows & MSVC using GitHub CI, but that's it. I don't have more time to invest with it, particularly if the problem is that you turned on the option to change warnings as errors. I already compile with -Wextra -Wall -pedantic on Linux, anything that pops up other than that is mostly junk coming from MSVC.

Want to fix it? Here are your options:

  • Write a PR. Hint: MSVC has a non-standard pragma called fp_contract that does the same thing, or claims it does. I'll review your PR quickly and you can see if it works on other platforms with the integrated CI on GitHub, so you don't have to install a VM or any other operating system to test your fix.
  • Turn off the option to emit warnings as errors in MSVC. Warnings will still be there. You can still fix them. They're just not errors.
  • Use clang. For the reasons mentioned above, you'll get a significant performance boost out of that (plus support for OpenMP 3.0 which is from 2008, still not supported to this day in MSVC).

from bvh.

tksuoran avatar tksuoran commented on May 23, 2024

I started looking at this but I run into a bit of an issue:
On my current incomplete attempt Visual Studio 2022 says:
bvh/utilities.hpp(42,17): warning C4177: #pragma 'fp_contract' should only be used at global scope or namespace scope
Meanwhile https://en.cppreference.com/w/cpp/preprocessor/impl says:

The behavior of the program is undefined if any of the three pragmas above appear in any context other than outside all external declarations or preceding all explicit declarations and statements inside a compound statement.

Does that mean that pragma STDC must precede function definitions? Function definition is declaration, right? If so, that would kind of match with what Visual Studio 2022 says, and the pragma should be relocated. The functions could be placed into a dedicated namespace, for example.

Edit: I've updated my pull request with a commit that uses a dedicated namespace for the pragma.

from bvh.

madmann91 avatar madmann91 commented on May 23, 2024

Note that using #pragma STDC FP_CONTRACT ON the way the library does it is fine, as it is inside a compound statement (block) and appears before anything else (except conditional preprocessor directives). The documentation on Microsoft's webpage regarding the scope and meaning of fp_contract is lacking and it's unclear where the legal places for it are (but anyway, since it is non-standard, it can appear everywhere MSVC accepts it).

from bvh.

tksuoran avatar tksuoran commented on May 23, 2024

This message tells something about the scope for MSVC:

#pragma 'fp_contract' should only be used at global scope or namespace scope

This is the motivation to use namespace. I am updating the PR so that namespace is only used with MSVC.

from bvh.

madmann91 avatar madmann91 commented on May 23, 2024

This should have been fixed by commit 5841efb.

from bvh.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.