Skip to content

Instantly share code, notes, and snippets.

@Yoone
Created February 25, 2018 05:12
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 Yoone/ca9359d7489c3c76de14b042cf0287ad to your computer and use it in GitHub Desktop.
Save Yoone/ca9359d7489c3c76de14b042cf0287ad to your computer and use it in GitHub Desktop.
Find out a machine's CPU architecture in C
#include <stdio.h>
int main(void)
{
/*
* AMD64
*/
#if defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64)
printf("AMD64\n");
#endif
/*
* ARM (32 bits I presume)
*/
#if defined(__arm__)
printf("ARM 32bits\n");
#endif
/*
* ARM64
*/
#if defined(__aarch64__)
printf("ARM64\n");
#endif
/*
* x86
*/
#if defined(i386) || defined(__i386) || defined(__i386__)
printf("x86\n");
#endif
#ifdef __i486__
printf("__i486__\n");
#endif
#ifdef __i586__
printf("__i586__\n");
#endif
#ifdef __i686__
printf("__i686__\n");
#endif
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment