473,574 Members | 2,634 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 7143
Malcolm McLean wrote, On 10/04/07 23:45:
>
"Martin Ambuhl" <ma*****@earthl ink.netwrote in message
news:58******** *****@mid.indiv idual.net...
>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().

He never gives up, does he. Malcolm, you are wrong. If he has a C90
compiler, he can always use "%lu" and cast to (unsigned long). That
was included in my answer. And "%x" is not a complete specifier. Did
you not bother with reading my answer before twice defending telling
an unsuspecting new programmer to use a broken construct. If you are
using a pre-C89 K&R compiler, that's your problem. Some day you might
start using a defined version of C.
We no longer have a standard.
Yes we do. At least, it seems to work fine for a lot of us.
When a standard fails it takes down the
system with it. Virtually no C programs are compiled under strictly
conforming ANSI compilers any longer.
Most never have been.
Then we don't want to go the size_t route.
Too late. size_t exists and it is the the type you get from sizeof. If
you don't like it, use another language.
For various reasons it is not
a humanly useable construct,
A number of people manage to use it. Perhaps none of us are human?
and one of two things will happen. Either
it will quietly be dropped and go away,
The first C standard came out in 1989 and since then size_t has not been
dropped, so that shows no sign of happening.
or it will run through C code
wrecking every array index or,
It hasn't wrecked any of mine.
in this case, call to printf,
Which as has been shown is easy to handle. The chances of sizeof being
applied to anything with a size too large for unsigned long are pretty slim.
which in
turn will provoke other changes, and turn the language into something
unrecognisable.
It's not Martin's fault if you have been unable to recognise C since it
was first standardised in 1989. I suspect size_t pre-dates the standard,
but I'm too lazy to check.
--
Flash Gordon
Apr 11 '07 #31
Malcolm McLean wrote:
>
.... snip ...
>
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.
alias cc=*gcc -W -Wall -ansi -pedantic -Wwrite-strings
-Wfloat-equal -gstabs+ -ftrapv -O1 %1&

--
<http://www.cs.auckland .ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfoc us.com/columnists/423>
<http://www.aaxnet.com/editor/edit043.html>

"A man who is right every time is not likely to do very much."
-- Francis Crick, co-discover of DNA
"There is nothing more amazing than stupidity in action."
-- Thomas Matthews

--
Posted via a free Usenet account from http://www.teranews.com

Apr 11 '07 #32
On Apr 10, 6:31 pm, jacob navia <j...@jacob.rem comp.frwrote:
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.

Actually several compilers support 32 bit pointers (at least as an
option), on 64 bit systems. For programs that don't need the extra
address space, and can be loaded in the first 2GB of memory, this can
lead to a significant reduction in memory and cache usage. For
example, the HP Alpha Tru64/Linux C/C++ compiler has the -xtaso_short
option.

Apr 11 '07 #33
broeisi wrote:
>
On 10 apr, 21:07, rober...@ibd.nr c-cnrc.gc.ca (Walter Roberson) wrote:
>In article <1176230815.876 762.147...@b75g 2000hsg.googleg roups.com>,

broeisi <broeis...@gmai l.comwrote:
>>Is there a way in C to get information at runtime if a processor is 32
or 64 bit?
No, not in standard C.

First you'd have to define exactly what it means for a processor
to be 32 or 64 bit, which is something that has at least 4 different
correct (but contradictory) answers.
--
I was very young in those days, but I was also rather dim.
-- Christopher Priest


Thank you very much for you answer Christopher.
But how does an OS like linux or windows know that it's installed on a
computer with a 32 or 64 bit processor?

The most usual distinction is whether a pointer fits in 32 bits. A
32-bit OS installed on a 64-bit processor doesn't care whether the
processor supports 64 bits. A 64-bit OS doesn't have to care either; it
wouldn't be running without its expected form of more-than-32-bit
support. And, a 32-bit C compiler running under the popular 64-bit
systems doesn't care about what is outside the subset of the platform
capabiity that it sees. It is responsible for generating code that
(normally) doesn't care whether it runs under a 32- or 64-bit OS, nor
does it have a way to know the difference without exceeding the bound of
Standard C and this forum.
Apr 11 '07 #34
Eric Sosman <Er*********@su n.comwrites:
[snip]
Martin Ambuhl has already pointed out that there is
no reason to expect any particular output.

But I have a question for the group at large: Once
the code is fixed, either via "%zd" or by casting,
Context: The code in question prints the size, in bits, of type int.
has
*anybody* *ever* used a machine where the output would
be "64-bit processor\n"?
Yup.
(An old Cray model, perhaps?)
Yup.

--
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."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Apr 11 '07 #35
Keith Thompson wrote:
Eric Sosman <Er*********@su n.comwrites:
[snip]
> Martin Ambuhl has already pointed out that there is
no reason to expect any particular output.

But I have a question for the group at large: Once
the code is fixed, either via "%zd" or by casting,

Context: The code in question prints the size, in bits, of type int.
> has
*anybody* *ever* used a machine where the output would
be "64-bit processor\n"?

Yup.
> (An old Cray model, perhaps?)

Yup.
Given your location, are any of those beasts still in use?

--
Ian Collins.
Apr 11 '07 #36
"ro***********@ yahoo.com" <ro***********@ yahoo.comwrites :
On Apr 10, 6:31 pm, jacob navia <j...@jacob.rem comp.frwrote:
>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.

Actually several compilers support 32 bit pointers (at least as an
option), on 64 bit systems. For programs that don't need the extra
address space, and can be loaded in the first 2GB of memory, this can
lead to a significant reduction in memory and cache usage. For
example, the HP Alpha Tru64/Linux C/C++ compiler has the -xtaso_short
option.
One might argue that such a program is running on an emulated 32-bit
system under a 64-bit system.

I agree that CHAR_BIT * sizeof(void*) will capture the "bit-ness" (as
in, 16-bit system vs. 32-bit system vs. 64-bit system) for most, if
not all, systems I've ever seen.

That doesn't, of course, make it meaningful for *all* systems. And
the C standard has no concept of a "32-bit system" or a "64-bit
system".

--
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."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Apr 11 '07 #37
"Malcolm McLean" <re*******@btin ternet.comwrite s:
"Martin Ambuhl" <ma*****@earthl ink.netwrote in message
news:58******** *****@mid.indiv idual.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.
It's undefined by *several* particular standards: C89/C90, C95, C99,
<OT>and however many C++ standards there have been</OT>.

In any case, ignoring everything after K&R1 is magnificently foolish.
sizeof() return an int in K and
R C.
Chapter and verse, please. K&R1, page 188, says:

This expression is semantically an integer constant and may be
used anywhere a constant is required.

I see no indication that this "integer constant" is necessarily of
type int.
You are more likely to break by passing %z to printf().
So convert to unsigned long and use "%lu". Or convert to int and use
"%d". As long as the size does not exceed 32767, the resulting code
is correct under *all* relevant standards, going all the way back to
K&R1 and probably farther.

--
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."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Apr 11 '07 #38
Keith Thompson wrote:
"ro***********@ yahoo.com" <ro***********@ yahoo.comwrites :
>>On Apr 10, 6:31 pm, jacob navia <j...@jacob.rem comp.frwrote:
>>>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.

Actually several compilers support 32 bit pointers (at least as an
option), on 64 bit systems. For programs that don't need the extra
address space, and can be loaded in the first 2GB of memory, this can
lead to a significant reduction in memory and cache usage. For
example, the HP Alpha Tru64/Linux C/C++ compiler has the -xtaso_short
option.

One might argue that such a program is running on an emulated 32-bit
system under a 64-bit system.
Not in the general case. I don't know about other operating systems,
but Solaris for one runs 32 bit binaries "native" on a 64 bit platform.

--
Ian Collins.
Apr 11 '07 #39
In article <ln************ @nuthaus.mib.or g>,
Keith Thompson <ks***@mib.orgw rote:
>"ro*********** @yahoo.com" <ro***********@ yahoo.comwrites :
>Actually several compilers support 32 bit pointers (at least as an
option), on 64 bit systems. For programs that don't need the extra
address space, and can be loaded in the first 2GB of memory, this can
lead to a significant reduction in memory and cache usage.
>One might argue that such a program is running on an emulated 32-bit
system under a 64-bit system.
One might, but then another one might argue that that would be wrong
for SGI IRIX64. There is a control bit in the process status word
that determines whether the processor is running with 32 bit or 64
bit pointers. It isn't an emulation in any traditional sense:
there are different microcode paths, both of which run at full speed.
--
"law -- it's a commodity"
-- Andrew Ryan (The Globe and Mail, 2005/11/26)
Apr 11 '07 #40

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

Similar topics

5
5221
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
3466
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
1430
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
1397
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
2305
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
6581
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
6993
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
6478
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
6172
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
7815
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
7738
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...
0
8077
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. ...
0
8257
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...
1
7828
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...
0
8113
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6476
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
1358
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1076
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.