Re: How to identity processor architecture

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




Enrico Granata
Computer Science & Engineering Department (EBU3B) - Room 3240
office phone 858 534 9914
University of California, San Diego

On Jan 27, 2011, at 12:20 AM, prabhu wrote:

Mandeep Sandhu wrote:
I guess a 64bit processor does need 64bit addresses to reference memory. But
at the same time, if 32 bit programs are to run unmodified on 64 bit
architectures there needs to be ways in which 32bit pointers can still work.
So, I am almost 100% sure that compiling 32bit code, even on a 64bit
processor, should yield 4 for sizeof(void*)
    

You are 100% right. Tried this on  2 laptops:

printf("Is this a %s-bit machine?\n", ((sizeof(void*) == 4) ? "32" : "64"));

32-Bit ubuntu (10.10) on 64-bit proc:
"Is this a 32-bit machine?"

64-Bit ubuntu (10.10) on 64-bit proc:
"Is this a 64-bit machine?"

Regards,
-mandeep
  

Hi Mandeep,

Thanks a lot.

So is there any other way available to identify the processor architecture using c code?? . The program needs to return correct
processor architecture(32bit or 64bit) irrespective to the OS architecture.

Thanks,
Prabhu

  
Enrico Granata
Computer Science & Engineering Department (EBU3B) - Room 3240
office phone 858 534 9914
University of California, San Diego

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@xxxxxxxxxxxxxxxxx
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


    

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@xxxxxxxxxxxxxxxxx
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


  


Someone already hinted at it, I guess:

 64-bit processors  have lm ("long mode") in the flags section of cpuinfo whereas   32-bit processors have not.
regards
Dharmvir Kumar
_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@xxxxxxxxxxxxxxxxx
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux