473,750 Members | 2,292 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 7260
Ian Collins <ia******@hotma il.comwrites:
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?
<OT>Not here at SDSC, no. (I miss the old Cray T90 with its
"waterfall" of Flourinert coolant behind a transparent panel.)</OT>

--
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 #41
On Apr 10, 9:56 pm, Keith Thompson <k...@mib.orgwr ote:
"robertwess...@ yahoo.com" <robertwess...@ 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. 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.

No, this is different than running a 32 bit binary on a 64 bit system
(which many systems can do, of course). This is basically a native 64
bit executable that happens to store only the low halves of pointers
(with appropriate tweaks to ensure it's never loaded or allocated
memory above 4GB). The executable still calls the normal 64 bit OS
API (and other) functions, widening pointers as needed.

Apr 11 '07 #42
"Eric Sosman" <Er*********@su n.comwrote in message
news:1176237613 .873475@news1nw k...
But I have a question for the group at large: Once
the code is fixed, either via "%zd" or by casting, has
*anybody* *ever* used a machine where the output would
be "64-bit processor\n"? (An old Cray model, perhaps?)
Didn't Alphas have a 64-bit int?

S

--
Stephen Sprunk "Those people who think they know everything
CCIE #3723 are a great annoyance to those of us who do."
K5SSS --Isaac Asimov
--
Posted via a free Usenet account from http://www.teranews.com

Apr 11 '07 #43
"Stephen Sprunk" <st*****@sprunk .orgwrites:
"Eric Sosman" <Er*********@su n.comwrote in message
news:1176237613 .873475@news1nw k...
But I have a question for the group at large: Once
the code is fixed, either via "%zd" or by casting, has
*anybody* *ever* used a machine where the output would
be "64-bit processor\n"? (An old Cray model, perhaps?)

Didn't Alphas have a 64-bit int?
I've access to an Alpha machine running NetBSD and it has 32 bits int and
64 bits long. Obviously other OS can do something other -- and compilation
flags may also play a roll. I seem to remember that Unix recommands the
LP64 model.

Yours,

--
Jean-Marc
Apr 11 '07 #44
broeisi wrote:
Is there a way in C to get information at runtime if a processor is 32
or 64 bit?
Not portably. Why do you want to know (ie what is it you're trying to do)?

--
The second Jena user conference! http://hpl.hp.com/conferences/juc2007/
"- born in the lab under strict supervision -", - Magenta, /Genetesis/

Hewlett-Packard Limited registered office: Cain Road, Bracknell,
registered no: 690597 England Berks RG12 1HN

Apr 11 '07 #45
"Stephen Sprunk" <st*****@sprunk .orgwrites:
"Eric Sosman" <Er*********@su n.comwrote in message
news:1176237613 .873475@news1nw k...
> But I have a question for the group at large: Once
the code is fixed, either via "%zd" or by casting, has
*anybody* *ever* used a machine where the output would
be "64-bit processor\n"? (An old Cray model, perhaps?)

Didn't Alphas have a 64-bit int?
It depends on the C implementation. On Alpha systems I've used
running DEC OSF (well, HP OSF, I guess), int is 32 bits and long is 64
bits. On a Cray T3E, which also used Alpha CPUs, int and long are
both 64 bits. (char is 8 bits, and short is 32 bits; the lack of any
16-bit integer type causes problems porting some software.)

--
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 #46
Ian Collins <ia******@hotma il.comwrites:
Keith Thompson wrote:
>"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. 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.
I didn't say one would *win* the argument. Obviously that "one" guy
doesn't know what he's talking about. I'm glad *I* didn't make such a
silly claim.

--
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 #47
broeisi wrote:
On 10 apr, 21:30, Flash Gordon <s...@flash-gordon.me.ukwro te:
>broeisi wrote, On 10/04/07 19:46:
>>Hello,
Is there a way in C to get information at runtime if a processor is 32
or 64 bit?
Is that really what you want to know? Depending on what your real
problem is a combination of the information in limits.h and the result
of the sizeof operator should help.
--
Flash Gordon


Flash Gordon,

Yes, that's really what I want to know.
Just trying to learn C by writing lots of silly little programs that
make sense to me..

I think that the answer given by Malcolm is a good one.
It follows that you haven't learned much.

Yes, that's a smart-ass remark. But it's also an
entirely serious remark: Malcolm has given an "answer"
that is faulty in both conception and execution. If you
consider his answer "good," you have much yet to learn.

A suggestion: If you are interested in learning C,
you will do better to concentrate on *C* and ignore the
ill-defined side-issues. As Malcolm's sad case shows us,
pursuing such matters can lead one so far afield that one
loses the ability to tell C from "C-ish" and winds up making
a fool of oneself in public.

Take this thread's question, for example: What will your
program do differently if it discovers that it is running on
a "64-bit processor" or a "32-bit processor," or for that
matter on an "8-bit processor" or an "18-bit processor?" That
is, what use would your program make of the answer to the
question?

Perhaps you ask whether you have a "64-bit processor" in
order to decide whether you can use a 64-bit `long' or allocate
a forty-gigabyte region with malloc(). If that's the goal, you
are asking the wrong question! If you want to know the range
of `long', use the LONG_MIN and LONG_MAX macros. If you want
to allocate forty gigabytes, first check SIZE_MAX or `(size_t)-1'
and then attempt the allocation. In short, ask the question whose
answer you will actually use, not some other question from which
you imagine you might deduce the answer.

Be direct, don't be circuitous, and DON'T be tricky.

--
Eric Sosman
es*****@acm-dot-org.invalid

Apr 11 '07 #48
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?

I can't imagine a 64 bit system where pointers are 32 bits.
64-bit SPARC running a 32-bit program.

--
Eric Sosman
es*****@acm-dot-org.invalid
Apr 11 '07 #49
Eric Sosman a écrit :
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?

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


64-bit SPARC running a 32-bit program.
Obvious, but as far as that program is concerned the processor *is* 32 bits!
Apr 11 '07 #50

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

Similar topics

5
5237
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
3476
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
1441
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 etc) at which the specific job should be started. We program each job, according to an interface....
1
1401
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 etc) at which the specific job should be started. We program each job, according to an interface....
11
2320
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 to connect.
5
6590
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 workstations. It seems that Windows "caches" the processor ID in the registry or somewhere else - I...
10
7009
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 CPU? Joel
11
6493
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 PCs need to be updated, so it would be nice to have the processor speed in all cases.
2
6178
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
8999
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
8836
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
9575
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
9394
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
9338
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,...
0
8260
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4885
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3322
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
3
2223
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.