1

In Xcode, I want to find out the value of the STDC FP_CONTRACT pragma after including just float.h and math.h. To my surprise, I couldn't find any way to do it!

So the question: Am I just missing something here, or is there actually no way to verify how a #pragma has been set? Of course, I can force it to be set any way I want, but it's not quite the same.

2
  • 4
    You can't query a pragma itself. So, unless the pragma updates some other state value that you can query with #if or `#if(n)def, there is nothing you can do. Commented Jul 18, 2024 at 17:28
  • Pragmas are instructions to the implementation, not variables. They don't have values per se that you could query. With respect to FP_CONTRACT specifically, the default for whether FP expression contraction is enabled is implementation defined, so you should find it in your implementation's docs. However, the expected usage is that you issue that pragma when you actually care, and otherwise let the compiler do its thing as it chooses. Plus, you can limit the scope of that pragma if necessary, so that you don't need to affirmatively cancel its effects. Commented Jul 18, 2024 at 18:17

1 Answer 1

0

Adding an answer since it was answered in comments:

There is absolutely no way to check at compile time how a pragma has been set. The exception would be if there are settings with predictable and identifiable effects, if you can verify the effect.

That’s not really possible with FP_CONTRACT because it allows contracting operations but doesn’t force it, so you can check the result of a*b+c but it may be contracted or not with FP_CONTRACT in effect.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.