473,544 Members | 2,074 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

32 or 64 bit processor info in C

Hello,

Is there a way in C to get information at runtime if a processor is 32
or 64 bit?

Cheers,

Broeisi

Apr 10 '07
168 7109
Ian Collins a écrit :
Malcolm McLean wrote:
>>"Martin Ambuhl" <ma*****@earthl ink.netwrote in message
news:58****** *******@mid.ind ividual.net...

>>>broeisi wrote:
I think that the answer given by Malcolm is a good one.
The answer given by Malcom is wrong, broken, and involves undefined
behavior. You don't need to thank people for lying to you.

Undefined by one particular standard. sizeof() return an int in K and R
C. You are more likely to break by passing %z to printf().

Leaving that detail aside, the answer is still wrong. Can you name a
widely used "64 bit" system where sizeof(int) * CHAR_BIT equals 64?
Neither SPARC 64 bits, nor Linux 64 bit nor WIndows 64 have an int
of 64 bits.

It would have been better to use "long", but that fails in
windows 64/Vista 64 since long is 32 bits in those systems.
Apr 10 '07 #21

"jacob navia" <ja***@jacob.re mcomp.frwrote in message
news:46******** **************@ news.orange.fr. ..
Ian Collins a écrit :
>Malcolm McLean wrote:
>>>"Martin Ambuhl" <ma*****@earthl ink.netwrote in message
news:58***** ********@mid.in dividual.net...
broeisi wrote:
>I think that the answer given by Malcolm is a good one.
The answer given by Malcom is wrong, broken, and involves undefined
behavior. You don't need to thank people for lying to you.
Undefined by one particular standard. sizeof() return an int in K and R
C. You are more likely to break by passing %z to printf().

Leaving that detail aside, the answer is still wrong. Can you name a
widely used "64 bit" system where sizeof(int) * CHAR_BIT equals 64?
Neither SPARC 64 bits, nor Linux 64 bit nor WIndows 64 have an int
of 64 bits.

It would have been better to use "long", but that fails in
windows 64/Vista 64 since long is 32 bits in those systems.
I know. Most systems are not conforming. Lack of 64 bit ints also has the
potential to wreck our beloved C language. Soon it will be necessary to use
a gibberish type every time you need an integer, and cast to another
gibberish type to pass to a library function.

--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm

Apr 10 '07 #22
broeisi a écrit :
Hello,

Is there a way in C to get information at runtime if a processor is 32
or 64 bit?

Cheers,

Broeisi
Tbe processor in the machine that I use to write this message
can transform itself from

o 16 bit processor (at startup)
o 32 bit processor (If I boot into Windows XP or linux 32)
o 64 bit processor (If I boot into Vista 64 or linux 64)

All those systems use EXACTLY THE SAME HARDWARE!

If the processor runs under a 32 bit system there is NO
WAY (unless you use assembly) to know that processor can be
64 bits.

For x86 systems the only way to know the kind of processor
you are running on is to issue the CPUID assembly instruction.

lcc-win32 has an "intrinsic" function (called cpuid() )
that will return you a structure with several bit fields that
specify the type of processor, etc. But this must be done
in a machine specific way. Other processors may support different
instructions and return values for similar instructions.

But this can't be done at all from C. Actually C is designed
to ABSTRACT from those details and make your programs run the
same in different machines by emulating missing features. That is why
you can use 64 bit integers (or even 128 ones) in a 32 bit system.

C will emulate the missing functionality for you, masking the
differences in hardware. This makes programs written in C portable
from a machine to the next.
Apr 10 '07 #23
jacob navia wrote:
Ian Collins a écrit :
>Malcolm McLean wrote:
>>"Martin Ambuhl" <ma*****@earthl ink.netwrote in message
news:58****** *******@mid.ind ividual.net...

broeisi wrote:

I think that the answer given by Malcolm is a good one.

The answer given by Malcom is wrong, broken, and involves undefined
behavior. You don't need to thank people for lying to you.

Undefined by one particular standard. sizeof() return an int in K and R
C. You are more likely to break by passing %z to printf().
Leaving that detail aside, the answer is still wrong. Can you name a
widely used "64 bit" system where sizeof(int) * CHAR_BIT equals 64?
Neither SPARC 64 bits, nor Linux 64 bit nor WIndows 64 have an int
of 64 bits.

It would have been better to use "long", but that fails in
windows 64/Vista 64 since long is 32 bits in those systems.
Better still void*. But still not a 100% solution.

--
Ian Collins.
Apr 10 '07 #24
Malcolm McLean wrote:
>
"jacob navia" <ja***@jacob.re mcomp.frwrote in message
news:46******** **************@ news.orange.fr. ..
>Ian Collins a écrit :
>>Malcolm McLean wrote:

"Martin Ambuhl" <ma*****@earthl ink.netwrote in message
news:58***** ********@mid.in dividual.net...
>
The answer given by Malcom is wrong, broken, and involves undefined
behavior. You don't need to thank people for lying to you.
>
Undefined by one particular standard. sizeof() return an int in K and R
C. You are more likely to break by passing %z to printf().

Leaving that detail aside, the answer is still wrong. Can you name a
widely used "64 bit" system where sizeof(int) * CHAR_BIT equals 64?
Neither SPARC 64 bits, nor Linux 64 bit nor WIndows 64 have an int
of 64 bits.

It would have been better to use "long", but that fails in
windows 64/Vista 64 since long is 32 bits in those systems.
I know. Most systems are not conforming. Lack of 64 bit ints also has
the potential to wreck our beloved C language. Soon it will be necessary
to use a gibberish type every time you need an integer, and cast to
another gibberish type to pass to a library function.
Non-conforming to what?

At least with most sensible 64 bit models we now have sizeof(sort) <
sizeof(int) < sizeof(long).

I've no idea where the notion of "gibberish type" comes into this.

--
Ian Collins.
Apr 10 '07 #25
Ian Collins a écrit :
>
Better still void*. But still not a 100% solution.
WOW, after all those pointless discussions you bring about a true
solution!!!

Why would be that wrong?

I can't imagine a 64 bit system where pointers are 32 bits.

It would fail only in 16 bit systems with 32 bit pointers...
like MSDOS, for instance.

In system mode, some 32 bit processors (x86) use 48 bit pointers
(with 16+32 segmented model pointers). But none of those constructs
are visible in user mode, as far as I know.

Apr 10 '07 #26
jacob navia wrote:
Ian Collins a écrit :
>>
Better still void*. But still not a 100% solution.

WOW, after all those pointless discussions you bring about a true
solution!!!

Why would be that wrong?
It's undoubtedly wrong on a DS9000 and probably wrong on a number of
Harvard architecture machines. This being clc, one has to minimise the
opportunities for the smart arses!

--
Ian Collins.
Apr 10 '07 #27
>Is there a way in C to get information at runtime if a processor is 32
>or 64 bit?
I doubt very much whether you can get a consistent answer for this
even if you use two armies of lawyers, a billion dollars, and 10
years of lawsuits. There are many different, and conflicting
definitions for what bittedness a processor is.

Apr 10 '07 #28
Gordon Burditt wrote:
>>Is there a way in C to get information at runtime if a processor is 32
or 64 bit?


I doubt very much whether you can get a consistent answer for this
even if you use two armies of lawyers, a billion dollars, and 10
years of lawsuits. There are many different, and conflicting
definitions for what bittedness a processor is.
Who asked the question?

--
Ian Collins.
Apr 10 '07 #29
On Apr 11, 10:45 am, "Malcolm McLean" <regniz...@btin ternet.com>
wrote:
We no longer have a standard. When a standard fails it takes down the system
with it. Virtually no C programs are compiled under strictly conforming ANSI
compilers any longer.
There's no such thing as a 'strictly conforming' compiler. Compilers
conform. Programs either conform, or conform strictly. (Or neither).

And yes, many people do in fact write conforming code and compile it
with conforming compilers.
Then we don't want to go the size_t route. For various reasons it is not a
humanly useable construct,
Except by the millions of humans who use it, one presumes.

Apr 10 '07 #30

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

Similar topics

5
5216
by: dba_db2 at nospam gmx.net | last post by:
We have got a brand new mutltiprocessor machine IBM pseries server with 2 processors. Now we want to buy a IBM DB2 license for this box. Does anyone know whether it is possible to buy a single processor db2 license for this machine and to configure the db2 software with db2licm just to use one processor.
1
3463
by: Mateusz Rajca | last post by:
Hello, I would like to know how to find the specs of the current running system such as the memory amount and processor speed in C#? Mateusz
3
1427
by: Michel Meex | last post by:
Hello, I have an application, that has been running on a single processor server for more then a year without any problems. Now I'm migrating to a dual processor server, and I'm experiencing problems with threading. The application is actually a kind of job schedular. For all jobs, I can set a recurring interval (daily,weekly, monthly...
1
1395
by: Michel Meex | last post by:
Hello, I have an application, that has been running on a single processor server for more then a year without any problems. Now I'm migrating to a dual processor server, and I'm experiencing problems with threading. The application is actually a kind of job schedular. For all jobs, I can set a recurring interval (daily,weekly, monthly...
11
2300
by: sunil | last post by:
Dear All, I have created a .Net service in 2.0 and running it on a machine that has a Quad Processor. It is failing with the following error. "Error 1053: The service did not respond to the start or control request in a timely fashion" This is what I saw in event Viewer. Timeout (30000 milliseconds) waiting for the MyService Server service...
5
6576
by: nano2k | last post by:
Hi I need to protect my application in a way. Just a "soft" protection, not a very strong one. So, using WMI I get the processor ID and compare it against a key. Protection works well, until someone (me) decides to clone the system. After cloning, all cloned systems work with the same key. That is, WMI returns the same processor id on all...
10
6989
by: WannaKatana | last post by:
I am just wondering why, with nothing else running and executing an update query against a very large table, does Access seem to be causing less than 10% processor usage. Then it says "There is not enough disk space or memory to undo the changes". I have 2 gb RAM, Core 2 duo e6300 processor and plenty of disk space. Why doesn't Access peg the...
11
6475
by: kyosohma | last post by:
Hi, We use a script here at work that runs whenever someone logs into their machine that logs various bits of information to a database. One of those bits is the CPU's model and speed. While this works in 95% of the time, we have some fringe cases where the only thing returned is the processor name. We use this data to help us decide which...
2
6170
by: raghavv | last post by:
Hi, I have developed a software.For licensing it i need to access a unique number of a computer like mother board id or processor id. Is there a way to get this info.In C# we can use system.management to get this info.Is there anything similar to this in java. If not How can i do this. Thank you...
0
7449
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...
0
7642
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. ...
1
7405
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...
1
5316
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...
0
4938
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3440
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...
1
1861
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1003
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
688
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.