Created
May 12, 2017 09:41
-
-
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
This file contains 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.
Learn more about bidirectional Unicode characters
#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