473,756 Members | 4,044 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to detect CPU architecture..

hi
i have to detect the type of CPU.
whether it is 32-bit or 64-bit..
how can this be done..

can anyone please help me..

thanks.

Sep 1 '06 #1
13 7196
On 31 Aug 2006 23:14:23 -0700, rr********@gmai l.com wrote:
>hi
i have to detect the type of CPU.
whether it is 32-bit or 64-bit..
how can this be done..

can anyone please help me..

thanks.
Standard C does not provide any way to detect whether the type of CPU
is 32-bit or 64-bit or even 8-bit or 16-bit or 128-bit. Since this
newsgroup is about Standard C, no one here can really help you.

--
jay
Sep 1 '06 #2
rr********@gmai l.com wrote:
i have to detect the type of CPU.
whether it is 32-bit or 64-bit..
how can this be done..
It can't. The CPU is 8-bit.

Richard






(Well, it could be. I still have computers like that. And define "the
type". And explain why you want to know. You probably _think_ you need
to, but you're equally probably mistaken.)
Sep 1 '06 #3
Try to use ULONG_MAX in gcc macro if you use Unix.
or sizeof(long): 4 for 32bit, 8 for 64bit arch.

Sep 1 '06 #4
In article <7a************ *************** *****@4ax.com>,
jaysome <ja*****@spamco p.netwrote:
>On 31 Aug 2006 23:14:23 -0700, rr********@gmai l.com wrote:
>>i have to detect the type of CPU.
whether it is 32-bit or 64-bit..
how can this be done..
>Standard C does not provide any way to detect whether the type of CPU
is 32-bit or 64-bit or even 8-bit or 16-bit or 128-bit. Since this
newsgroup is about Standard C, no one here can really help you.
Furthermore, Standard C does not provide any what to determine what any
particular person -means- by a CPU being 32 bit or 64 bit or something
else. Bits in int? Bits in long? Bits in long long? Bits in a pointer?
Maximum theoretical addressible memory? Bits in the data bus between
the CPU and memory? Maximum number of bits in a result produced by an
operation? (that's a trick question -- integer multiple and divide
instructions are often exceptions to the rest of the architecture.)

Then there are systems like all of the SGI MIPS-based computers
produced in the last decade, all of which have CPUs which can
switch between 32 bit pointers and 64 bit pointers (per process),
any particular test run would not tell you what the CPU is capable
of, only how that particular test program was set up to run.
--
Prototypes are supertypes of their clones. -- maplesoft
Sep 1 '06 #5
posted:
hi
i have to detect the type of CPU.
whether it is 32-bit or 64-bit..
how can this be done..

I suppose the closest thing might be something like:

#include <limits.h>

#if UINT_MAX == 4294967295U
/* We have 32-Bit */
#elsif UINT_MAX == 184467440737095 51615U
/* We have 64-Bit */
#else
/* Neither */
#endif

--

Frederick Gotham
Sep 1 '06 #6
Frederick Gotham wrote:
posted:

>>hi
i have to detect the type of CPU.
whether it is 32-bit or 64-bit..
how can this be done..

I suppose the closest thing might be something like:

#include <limits.h>

#if UINT_MAX == 4294967295U
/* We have 32-Bit */
#elsif UINT_MAX == 184467440737095 51615U
/* We have 64-Bit */
#else
/* Neither */
#endif
No. This would "detect" a 32 bit system in a 64 bit
unix. Use "long" for that. In 64 bit Unix, you have
(in some implementations , specifically gcc)
long 64 bits
int 32 bits

64 bit windows has
long 32 bits
int 32 bits

jacob
Sep 1 '06 #7
In article <FI************ *******@news.in digo.ie>,
Frederick Gotham <fg*******@SPAM .comwrote:
[someone not named by Frederick posted]
>i have to detect the type of CPU.
whether it is 32-bit or 64-bit..
>I suppose the closest thing might be something like:
>#include <limits.h>
>#if UINT_MAX == 4294967295U
/* We have 32-Bit */
#elsif UINT_MAX == 184467440737095 51615U
/* We have 64-Bit */
#else
/* Neither */
#endif

SGI IRIX in -64 mode would have UINT_MAX as 4294967295U .

Perhaps you meant to use ULONG_MAX instead of UINT_MAX ?
--
Is there any thing whereof it may be said, See, this is new? It hath
been already of old time, which was before us. -- Ecclesiastes
Sep 1 '06 #8
jacob navia posted:
No. This would "detect" a 32 bit system in a 64 bit
unix.

Yes, I realise that. It was a merely fully-portable attempt to detect CPU
bitness.

--

Frederick Gotham
Sep 1 '06 #9
"dkrot" <j.*****@ramble r.ruwrites:
Try to use ULONG_MAX in gcc macro if you use Unix.
or sizeof(long): 4 for 32bit, 8 for 64bit arch.
Please quote enough context so we can tell what you're talking about
even if we haven't seen the parent article.

ULONG_MAX (which is standard C, not specific to either gcc or Unix)
only tells you what the compiler writer has chosen as the maximum
value of type unsigned long. It tells you nothing about the
underlying CPU architecture. The compiler writer's choices for the
attributes of the predefined types are typically guided by the CPU
architecture, but they're not mandated by it.

It's not even clear what "32-bit architecture" or "64-bit
architecture" actually means. It might have some accepted meaning for
particular sets of architectures (e.g., the x86 family), but that
won't necessarily apply to other architectures (PowerPC, SPARC,
AS/400, DS9K, etc.).

And even if you can rigorously define the terms, there's not likely to
be any way to distinguish between them in portable C.

The entire question is largely meaningless and off-topic.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Sep 1 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

25
5625
by: David Noble | last post by:
We've been developing a web site using 3-tier architecture for 18 months now. There is a common layer that defines the classes - using XML schemas. The data layer acts as a wrapper to 3 databases - SQL Server, Oracle and AS400. The business layer exposes web services which communicate with the front end, ASP.Net. All 3 tiers are on different boxes. This works well. Now I am leading a team to build a winforms app. I need some advice as
2
1529
by: Vicent | last post by:
Hi all: I would like to Know if a host is still alive in the network. We can suposse that we Know the name of the PC. Any source code would be appreciatted. Thanks in advance: Vicent Vidal
4
2306
by: apngss | last post by:
what's the differences between collocated architecture and distributed architecture?? My understanding is that collocated architecture has everything in a single machine? i.e. There is only 1 machine in middle business tier? But distributed architecture distributes the load in multiple machines? i.e. There are multiple machines in middle business tier?
6
2545
by: Adam Warner | last post by:
Hi all, Is this a (C99) portable way to detect whether the C stack grows upwards (1) or downwards (-1)? #include <stdio.h> int stack_direction=0; void detect_stack_direction(void * stack_start) {
6
3662
by: carsonbj | last post by:
I have an issue where the below operation works on a little-endian architecture but not on a big-endian architecture. I was under the impression that pointer arithmetic is architecture independant and bitwise operations are architecture dependant. The intention is to store two bytes, as chars, extracted from a short input parameter as: <code> void foo(short id_pair) { char *ptr = &id_pair;
6
1059
by: rrs.matrix | last post by:
hi i have to detect the type of CPU. whether it is 32-bit or 64-bit.. how can this be done.. can anyone please help me.. thanks.
0
4928
by: srikar | last post by:
Hi all, I am having a problem, when I am compiling the code in 32 bit option on a 64 bit machine using the macro CPPFLAGS= -m32 I am getting the following warnings from the linker . /`../bin/amd64_stat_gnu_02015/WriteFault.o' is incompatible with i386:x86-64 output /usr/bin/ld: warning: i386 architecture of input file `../bin/amd64_stat_gnu_02015/WriteLogic.o' is incompatible with i386:x86-64 output /usr/bin/ld: warning: i386...
15
17439
by: Eric Renken | last post by:
Is there something in System.Environment that can tell me if the program is running on a 64bit OS? What I am thinking is right now is to check the size of IntPtr and if it is 4 then it is 32bit, but if it is 8 then it is 64bit. Thanks, Eric Renken
5
2474
by: =?Utf-8?B?S3VtYXIuQS5QLlA=?= | last post by:
Kumar.A.P.P Software Engineer, Infosys Technologies Limited. http://techaid.wordpress.com/
0
9431
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9255
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10014
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9844
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9819
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7226
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5119
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5289
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3326
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.