Check what compiler flag is set within C++ code

Viewed 319

Is there a way to check what flags are set on the compiler in running C++ code?

Specifically, was this code compiled with /fp:precise or /fp:fast from within the program?

1 Answers

In the msvc documentation you can do this using predefined macros: https://docs.microsoft.com/en-us/cpp/preprocessor/predefined-macros?view=msvc-160

_M_FP_FAST Defined as 1 if the /fp:fast compiler option is set. Otherwise, undefined.

_M_FP_PRECISE Defined as 1 if the /fp:precise compiler option is set. Otherwise, undefined.

Note that these are compiler specific so don't expect them to work on any other compiler.

Related