Project Home
Project Home
Trackers
Trackers
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - How to tell what architecture the code is running on.: (4 Items)
   
How to tell what architecture the code is running on.  
Hello, 

I am developing on two architectures, x86 and arm.
Is there a system variable I can read at runtime to determine the platform (ARM vs x86)?

Thanks, 
- Mike
RE: How to tell what architecture the code is running on.  
Re: How to tell what architecture the code is running on.  
On Wed, Apr 01, 2009 at 09:23:59AM -0400, Michael Cranston wrote:
> I am developing on two architectures, x86 and arm.
> Is there a system variable I can read at runtime to determine the platform (ARM vs x86)?


// For compile time selection....
main() {
#if defined(__X86__)
	printf("I'm an X86!\n");
#elif defined(__ARM__)
	printf("I'm an ARM!\n");
#else
	printf("I'm something else!\n");
#endif
}

// For run time selection....
#include <sys/syspage.h>
main() {
	switch(_syspage_ptr->type) {
	case SYSPAGE_X86:
		printf("I'm an X86!\n");
		break;
	case SYSPAGE_ARM:
		printf("I'm an ARM!\n");
		break;
	default:
		printf("I'm something else!\n");
		break;
	}
}
		
-- 
Brian Stecher (bstecher@qnx.com)        QNX Software Systems
phone: +1 (613) 591-0931 (voice)        175 Terence Matthews Cr.
       +1 (613) 591-3579 (fax)          Kanata, Ontario, Canada K2M 1W8
Re: How to tell what architecture the code is running on.  
On Wed, Apr 01, 2009 at 09:24:02AM -0400, Michael Cranston wrote:
> Hello, 
> 
> I am developing on two architectures, x86 and arm.
> Is there a system variable I can read at runtime to determine the platform (ARM vs x86)?

At compile time you can do something like:

enum arch_enum {
	ARCH_X86,
	ARCH_ARM;
};

#if defined(__X86__)
	architecture = ARCH_X86;
#elif defined(__ARM__)
	architecture = ARCH_ARM;
#else
#error unknown arch
#endif

-seanb