Skip to content

Instantly share code, notes, and snippets.

@iddm
Created November 22, 2022 13:56
Show Gist options
  • Save iddm/d24cfdabf56a82d6f8d043be46aebcf0 to your computer and use it in GitHub Desktop.
Save iddm/d24cfdabf56a82d6f8d043be46aebcf0 to your computer and use it in GitHub Desktop.
Print out the C standard being used.
// Credits to "Robk" https://stackoverflow.com/users/13382603/robk
// From https://stackoverflow.com/questions/4991707/how-to-find-my-current-compilers-standard-like-if-it-is-c90-etc
static void _printversion() {
if (!__STDC__ && !__STDC_VERSION__) printf("The C compiler does not comply with the C89 or later standard!\nIt likely complies with the 1978 K&R C standard (informally known as C78).\n");
else if (__STDC_VERSION__ >= 201710L) printf("The C compiler complies with the C17 standard.\n");
else if (__STDC_VERSION__ >= 201112L) printf("The C compiler complies with the C11 standard.\n");
else if (__STDC_VERSION__ >= 199901L) printf("The C compiler complies with the C99 standard.\n");
else if (__STDC_VERSION__ >= 199409L) printf("The C compiler complies with the amended C90 standard (also known as C95).\n");
else if (__STDC__) printf("The C compiler complies with the ANSI C89 / ISO C90 standard.\n");
puts("");
if (__STDC__) printf("\"__STDC__\": %ld\n", __STDC_VERSION__);
if (__STDC_VERSION__) printf("\"__STDC_VERSION__\": %ld\n\n", __STDC_VERSION__);
puts("");
if (__STDC_VERSION__ >= 199901L) printf(" INFINITY (added in C99): %f\n", INFINITY ); // Also works with %lf and %Lf
if (__STDC_VERSION__ >= 199901L) printf("-INFINITY (added in C99): %f\n", -INFINITY ); // Also works with %lf and %Lf
puts("");
if (__STDC_VERSION__ >= 199901L) printf(" HUGE_VALF (added in C99): %f\n", HUGE_VALF );
if (__STDC_VERSION__ >= 199901L) printf("-HUGE_VALF (added in C99): %f\n", -HUGE_VALF );
puts("");
if (__STDC__) printf(" HUGE_VAL (added in C89 (ANSI) which is the same as C90 (ISO)): %lf\n", HUGE_VAL );
if (__STDC__) printf("-HUGE_VAL (added in C89 (ANSI) which is the same as C90 (ISO)): %lf\n", -HUGE_VAL );
puts("");
if (__STDC_VERSION__ >= 199901L) printf(" HUGE_VALL (added in C99): %Lf\n", HUGE_VALL );
if (__STDC_VERSION__ >= 199901L) printf("-HUGE_VALL (added in C99): %Lf\n", -HUGE_VALL );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment