473,699 Members | 2,197 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 7232
Richard Heathfield wrote:
CBFalconer said:
>Malcolm McLean wrote:
>>>
... snip ...
>>>
Now consider this

foo(char *str1, char *str2)
{
hackme = strlen(str1) - count_spaces(st r2);
if(hackme < 0)
bar(str1, str2);
else
baz(str12, str2);
}

Again nothing too exceptional about this code. Typical rather
horrid flow control logic. What type would you say hackme should
be?

You can simplify, because strlen can never return a value less than
0. It returns a size_t, which is an unsigned quantity. Thus you
can reliably replace the whole routine with:

bar(str1, str2);

and save a minimum of 9 lines of useless source code.

But your "replacemen t" does not actually have the same functionality
as Malcolm's code. You might want to read it again, more carefully.
So it doesn't. Another good idea hits the dust.

--
<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 18 '07 #111

"Ian Collins" <ia******@hotma il.comwrote in message
news:58******** ******@mid.indi vidual.net...
Malcolm McLean wrote:
>>
"Keith Thompson" <ks***@mib.orgw rote in message
news:ln******* *****@nuthaus.m ib.org...
>>On the other hand, sometimes it's ok to use int to index into an
array, if, for example, you happen to know that the array cannot have
more than 32768 elements. The indexing operation takes one pointer
operand (often a converted array name) and one integer operand; the
integer operand can be of any integer type, including int, size_t, and
even _Bool if your compiler supports it.
This is the problem.

int count_spaces(ch ar *str)
{
int i;
int answer = 0;

for(i=0;str[i];i++)
if(str[i] == ' ')
answer++;

return answer;
}

Perfectly unexceptional code. In fact it is unlikely that anyone is
going to want that routine on anything other than a line limited
elsewhere to be a thousand or so characters.
But someone might, just might, pass in a really long string. So those
ints have got to be size_ts to be strictly correct. So size_t is
propagating up out type.
So? Consider a 16 bit machine with a 20 bit address space, should int
on that machine be 21 bits?
Ideally yes. In practise it is better to have the extra efficiency and put
burdens on those people who want an array spanning over half the address
space. Once an architecture get weird there is no answer - in practise such
machines had near and far pointers and constrained single arrays to be less
that 64K, allowing 16 bit indexing. It worked, but it was far from ideal,
and threw a hammer in portability.
>
Why would a function that counts something return a signed type?
Because intermediate calculations using it might go below zero.

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

Apr 18 '07 #112
Malcolm McLean wrote:
>
"Ian Collins" <ia******@hotma il.comwrote in message
news:58******** ******@mid.indi vidual.net...
>Malcolm McLean wrote:
>>This is the problem.

int count_spaces(ch ar *str)
{
int i;
int answer = 0;

for(i=0;str[i];i++)
if(str[i] == ' ')
answer++;

return answer;
}
So? Consider a 16 bit machine with a 20 bit address space, should int
on that machine be 21 bits?
Ideally yes. In practise it is better to have the extra efficiency and
put burdens on those people who want an array spanning over half the
address space.
So there you have it - 32 bit int on a typical contemporary 64 bit
machine *does* provide extra efficiency of over a 64 bit int.
>>
Why would a function that counts something return a signed type?
Because intermediate calculations using it might go below zero.
Bud does it make any sense?

--
Ian Collins.
Apr 18 '07 #113
Ian Collins wrote:
>
Bud does it make any sense?
My word, my typos are in overdrive this evening!

--
Ian Collins.
Apr 18 '07 #114

"Ian Collins" <ia******@hotma il.comwrote in message
news:58******** ******@mid.indi vidual.net...
Malcolm McLean wrote:
>>
Ideally yes. In practise it is better to have the extra efficiency and
put burdens on those people who want an array spanning over half the
address space.

So there you have it - 32 bit int on a typical contemporary 64 bit
machine *does* provide extra efficiency of over a 64 bit int.
Engineering is like that. A bad design decision usually has something going
for it, and there are good arguments we can use in its favour.
I'd like to see some benchmarks on real applications to see whether hitting
the cache capacity has a big effect or a small effect.

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

Apr 18 '07 #115

"Eric Sosman" <Er*********@su n.comwrote in message
news:1176843829 .711898@news1nw k...
Malcolm McLean wrote On 04/17/07 16:25,:
>>
Again nothing too exceptional about this code. Typical rather horrid flow
control logic. What type would you say hackme should be?

"No type at all."

foo(char *str1, char *str2) {
if (strlen(str1) < count_spaces(st r2))
bar(str1, str2);
else
baz(str12 /* sic */, str2);
}
That's acceptable code, but you are reversing my decision to improve
readbility by splitting the computation into two statements.
Whilst in this case you might be right, readability is highly important, and
layout should not be dictated by the weaknesses of the type sytem. Anyway,
we could easily modify the example so that hackme is required twice.

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

Apr 18 '07 #116
Malcolm McLean wrote On 04/18/07 15:06,:
"Eric Sosman" <Er*********@su n.comwrote in message
news:1176843829 .711898@news1nw k...
>>Malcolm McLean wrote On 04/17/07 16:25,:
>>>Again nothing too exceptional about this code. Typical rather horrid flow
control logic. What type would you say hackme should be?

"No type at all."

foo(char *str1, char *str2) {
if (strlen(str1) < count_spaces(st r2))
bar(str1, str2);
else
baz(str12 /* sic */, str2);
}

That's acceptable code, but you are reversing my decision to improve
readbility by splitting the computation into two statements.
You "improve" readability by using many statements
where one suffices? Does your family tree blossom with
lawyers, politicians, marketeers, and spin doctors?
Whilst in this case you might be right, readability is highly important, and
layout should not be dictated by the weaknesses of the type sytem. Anyway,
we could easily modify the example so that hackme is required twice.
int hackme = strlen(str1) < count_spaces(st r2);

(Optional: Use _Bool instead of int for C99.)

--
Er*********@sun .com

Apr 18 '07 #117
Eric Sosman said:
Malcolm McLean wrote On 04/18/07 15:06,:
>>
That's acceptable code, but you are reversing my decision to improve
readbility by splitting the computation into two statements.

You "improve" readability by using many statements
where one suffices?
This is sometimes the case, yes, although it may depend on what you mean
by "suffices".

Consider, for example, the following (genuine) code:

new->pixel[y] = clc_malloc(widt h * sizeof *new->pixel[y]);
if(new->pixel[y] == NULL)
Now, you /could rewrite this as:

if((new->pixel[y] = clc_malloc(widt h * sizeof *new->pixel[y])) == NULL)

....which certainly suffices, but I am not convinced that readability is
improved by the contraction.

Does your family tree blossom with
lawyers, politicians, marketeers, and spin doctors?
I think that's a touch unfair. I'm actually on your side in this
discussion, but I think you overstate the case here.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Apr 18 '07 #118
Richard Heathfield <rj*@see.sig.in validwrote:
<snip>
Now, you /could rewrite this as:

if((new->pixel[y] = clc_malloc(widt h * sizeof *new->pixel[y])) == NULL)

...which certainly suffices, but I am not convinced that readability is
improved by the contraction.
I would agree with you. Which is why I generally swap the operands:

if (0 != (new->pixel[y] = clc_malloc(widt h * sizeof *new->pixel[y])))
...

Operands are used in order of most importance to thine eyes and head.
Personally, this reads much more easily than multiple statements.

Apr 18 '07 #119
Richard Heathfield wrote On 04/18/07 15:43,:
Eric Sosman said:

>>Malcolm McLean wrote On 04/18/07 15:06,:
>>>That's acceptable code, but you are reversing my decision to improve
readbility by splitting the computation into two statements.

You "improve" readability by using many statements
where one suffices?


This is sometimes the case, yes, although it may depend on what you mean
by "suffices".

Consider, for example, the following (genuine) code:

new->pixel[y] = clc_malloc(widt h * sizeof *new->pixel[y]);
if(new->pixel[y] == NULL)
Now, you /could rewrite this as:

if((new->pixel[y] = clc_malloc(widt h * sizeof *new->pixel[y])) == NULL)

...which certainly suffices, but I am not convinced that readability is
improved by the contraction.
Yah. "Bless you, it all depends." It is useful to
decompose lengthy statements into smaller, more easily-
comprehended pieces (not just for the reader's sake, but
for the writer's as well!), but decomposition for its own
sake is, well, compost.

McClean's example showed a perfectly simple, obvious
and easily-comprehended test, which he chose to decompose
into two statements. In the process he introduced a brand-
new variable (the point of his example was to try to expose
a difficulty concerning that unnecessary variable), plus two
additional operators. That sort of rearrangement is not
only obfuscatory (hiding a comparison behind a subtraction,
a la FORTRAN's three-way IF), but bug-inducing.

As for the malloc example, I myself usually write an
assignment statement and a separate test. This is not so
much out of a concern that the whole thing would be too
long, but to direct the focus: "I will now allocate some
memory. (By the way, I'll also check for failure.)" But
sometimes I'll gang the whole thing together, particularly
during an initialization where I'm just going to exit the
program on a failure:

if ( (buff1 = malloc(N1 * sizeof *buff1) == NULL
|| (buff2 = malloc(N2 * sizeof *buff2) == NULL
|| (buff3 = malloc(N3 * sizeof *buff3) == NULL ) {
perror ("malloc");
fputs ("No memory; bye-bye!\n", stderr);
exit (EXIT_FAILURE);
}

I think this is easier to read than three assignments, three
tests, and three error-exits, or than shuffling the test-and-
exit off to a wrapper function -- although I do *that* too,
sometimes. (Note that three assignments followed by one
three-way test and one error-exit is not quite the same: if
malloc() sets errno, the successful allocation of buff3 could
obscure why buff2's allocation failed. malloc() need not set
errno and some do not, but I take the optimistic view and try
to give the poor user all the available diagnoses, even if
they're suspect.)
>>Does your family tree blossom with
lawyers, politicians, marketeers, and spin doctors?

I think that's a touch unfair. I'm actually on your side in this
discussion, but I think you overstate the case here.
Tastes vary. Or, "There's no point arguing with Gus."

--
Er*********@sun .com
Apr 18 '07 #120

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

Similar topics

5
5230
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
3471
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
1433
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
1398
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
2314
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
6587
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
7003
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
6487
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
8706
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
8631
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
9199
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
9055
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
8945
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
6550
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
5889
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4392
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...
1
3075
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

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.