Roger Maclean
|
RE: How to tell what architecture the code is running on.
|
Roger Maclean
04/01/2009 9:33 AM
post25749
|
RE: How to tell what architecture the code is running on.
|
|
|
Brian Stecher
|
Re: How to tell what architecture the code is running on.
|
Brian Stecher
04/01/2009 9:34 AM
post25750
|
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
|
|
|
Sean Boudreau(deleted)
|
Re: How to tell what architecture the code is running on.
|
Sean Boudreau(deleted)
04/01/2009 9:36 AM
post25752
|
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
|
|
|