A floating point option shield to check for sensible C compiler configurations

fanf21 pts0 comments

first pass "floating point option" shield · GitHub

/" data-turbo-transient="true" />/" data-turbo-transient="true" />

Skip to content

-->

Search Gists

Search Gists

Sign in

Sign up

You signed in with another tab or window. Reload to refresh your session.<br>You signed out in another tab or window. Reload to refresh your session.<br>You switched accounts on another tab or window. Reload to refresh your session.

Dismiss alert

{{ message }}

Instantly share code, notes, and snippets.

Marc-B-Reynolds/fp_compiler_check.h

Secret

Last active<br>July 5, 2026 18:22

Show Gist options

Download ZIP

Star

(1)

You must be signed in to star a gist

Fork

(0)

You must be signed in to fork a gist

Embed

Select an option

Embed<br>Embed this gist in your website.

Share<br>Copy sharable link for this gist.

Clone via HTTPS<br>Clone using the web URL.

No results found

Learn more about clone URLs

Clone this repository at &lt;script src=&quot;https://gist.github.com/Marc-B-Reynolds/1e2ef2a7e59d100e39d26cf69079ded6.js&quot;&gt;&lt;/script&gt;

" readonly="readonly" data-autoselect="true" data-target="primer-text-field.inputElement " aria-describedby="validation-fb6b09b1-cc10-4c72-bf7d-fbdbe1835df7" class="form-control FormControl-monospace FormControl-input FormControl-small rounded-left-0 rounded-right-0 border-right-0" type="text" name="gist-share-url-sized-down" />

Save Marc-B-Reynolds/1e2ef2a7e59d100e39d26cf69079ded6 to your computer and use it in GitHub Desktop.

Embed

Select an option

Embed<br>Embed this gist in your website.

Share<br>Copy sharable link for this gist.

Clone via HTTPS<br>Clone using the web URL.

No results found

Learn more about clone URLs

Clone this repository at &lt;script src=&quot;https://gist.github.com/Marc-B-Reynolds/1e2ef2a7e59d100e39d26cf69079ded6.js&quot;&gt;&lt;/script&gt;

" readonly="readonly" data-autoselect="true" data-target="primer-text-field.inputElement " aria-describedby="validation-1a6c3a00-ac8d-4411-8fc9-ac93921cdbc1" class="form-control FormControl-monospace FormControl-input FormControl-small rounded-left-0 rounded-right-0 border-right-0" type="text" name="gist-share-url-original" />

Save Marc-B-Reynolds/1e2ef2a7e59d100e39d26cf69079ded6 to your computer and use it in GitHub Desktop.

Download ZIP

first pass "floating point option" shield

Raw

fp_compiler_check.h

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.<br>Learn more about bidirectional Unicode characters

Show hidden characters

// -*- coding: utf-8 -*-

// Marc B. Reynolds, 2026

// Public Domain under http://unlicense.org, see link for details.

//

// This header include compile-time and runtime checks for compiler

// options that "break" floating-point portability. This optionally

// includes options that are "correct" but hurt performance supporting

// features that the vast majority of user shouldn't want.

//

// USAGE: include this file in any source file (and/or any header

// which contains inline functions which need protecting) and:

// ∙ any "bad" compiler options that can be detected by a predefined

// macro will trigger a static_assert with a message. These

// can be disabled by defining FP_CC_COMPILE_TIME_DISABLED

// before including this header.

// ∙ at initialization time (before 'main' is executed) each

// translation unit which includes this header run a series

// of runtime checks.

//

// LIMITATIONS:

// ∙ There's no automagic way (I can think of) to expand the name

// of the source file so need to define FP_CC_FILE for output

// to not report "(unknown)" (__FILE__ expands to this header)

// ∙ runtime checks (obviously) expand by the compiler settings

// at the point this header is included. So can't catch if they

// are modified in the source file (pragmas, etc) at some later

// point in the file. Main "concern" here is attempting to

// protect some "inline" function (in header to "user").

// ∙ lowest optimization levels might trigger errors and warnings.

// GCC: as of 14.2.0 with -O0 -fno-math-errno the no math errno

// gets ignored and we would get a warning if it wasn't short

// circuited below.

// ∙ Currently with GCC the init time functions are called before

// the one in `fastmathcrt` so it will not detect flushing

// denormals to zero since the control word has not been yet

// changed.

// ∙ In MSVC the runtime checks will not happen if global optimizations

// have been enabled (/GL). The compiler thinks they are

// unreachable and are removed. (can't think of a zero user friction

// way to correct this).

// ∙ many more!

//

// NOTES:

// ∙ assumes at least C99

// ∙ there are purposefully redundant compile & runtime checks

// (lack of faith in compilers, evolution of compilers and myself)

//

//────────────────────────────────────────────────────────────────────────

// SUPPORTED CHECKS and...

gist clone file header point data

Related Articles