Check for 64-bit

29th January 2011 | Tutorial

If you have a Macintosh application and you need to check if the OS is running in either 32 or 64 bit mode, here is a code snippet to make that determination.


/* File: check64bit.c
 * Description: Check if the running version of Mac OS X is 64-bit
 * To Compile: gcc -Wall -o check64bit check64bit.c
 * To run: ./check64bit
 */
 
 #include <stdio.h>
 #include <string.h>
 #include <sys/utsname.h>
 
 int main(int argc, char *argv[])
 {
 	int ret = 0;
 	struct utsname uname_info;
 	
 	ret = uname(&uname_info);
 	
 	if (ret == 0)
 	{
		printf("Uname Info\n");
		printf("Sysname  : %s\n", uname_info.sysname);
		printf("Nodename : %s\n", uname_info.nodename);
		printf("Release  : %s\n", uname_info.release);
		printf("Version  : %s\n", uname_info.version);
		printf("Machine  : %s\n", uname_info.machine);
		
		if (strcmp(uname_info.machine, "x86_64") == 0)
		{
			printf("You are running in 64-bit mode!\n");
		}
		else
		{
			printf("You are running in 32-bit mode.\n");
		}
 	}
 	
 	return 0;
 }
 
 

Reference

Edenwaith Gist : https://gist.github.com/edenwaith/8125865