Skip to content

Instantly share code, notes, and snippets.

@wolf99
Created May 12, 2017 09:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wolf99/018486a6eb328d69f24ec35485b23df8 to your computer and use it in GitHub Desktop.
Save wolf99/018486a6eb328d69f24ec35485b23df8 to your computer and use it in GitHub Desktop.
Quick C program to detect if standard C threads are supported by checking the `__STDC_NO_THREADS__` macro
#include <stdio.h>
int main (int argc, char *argv[])
{
// Get the compiler name and version, where easily obtained, for a more
// informative output
char *compilerName;
char *compilerVersion;
#if defined(__clang__)
compilerName = "Clang/LLVM";
compilerVersion = __VERSION__;
#elif defined(__ICC) || defined(__INTEL_COMPILER)
compilerName = "Intel ICC/ICPC";
compilerVersion = __VERSION__;
#elif defined(__GNUC__) || defined(__GNUG__)
compilerName = "GNU GCC/G++";
compilerVersion = __VERSION__;
#elif defined(__HP_cc) || defined(__HP_aCC)
compilerName = "HP C/aC++";
#elif defined(__IBMCC__) || defined(__IBMCPP__)
compilerName = "IBM XL C/C++";
compilerVersion = __xlc__;
#elif defined(_MSC_VER)
compilerName = "MS Visual Studio";
#elif defined(__PGI)
compilerName = "Portland Group PGCC/PGCPP";
#elif defined(__SUNPRO_C) || defined(__SUNPRO_CC)
compilerName = "Oracle Solaris Studio";
#endif
printf("Threads are %ssupported", __STDC_NO_THREADS__ ? "not " : "");
printf(" in C standard %ld", __STDC_VERSION__);
if (compilerName)
printf(" on %s", compilerName);
if (compilerVersion)
printf(" %s", compilerVersion);
printf("\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment