Re: 32 or 64 bit processor info in C
- From: Martin Ambuhl <mambuhl@xxxxxxxxxxxxx>
- Date: Wed, 11 Apr 2007 15:09:58 -0400
broeisi wrote:
On 10 apr, 23:15, Martin Ambuhl <mamb...@xxxxxxxxxxxxx> wrote: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.
Ahhh... I'm just starting out.. didn't know that the answer wasn't
correct.
So it's just not possible to know whether you're dealing with a 32 or
64 bit processor from C.
hmmm.. thought that C could handle any programming problem?
If you consider any particular kind of object (or pointer) to correspond to something you think makes something a "32 or 64 bit processor", then you can take its size in chars with sizeof and multiply by CHAR_BIT.
Suppose you think that a pointer-to-void satisfies this requirement, remembering that whatever you mean by "32 or 64 bit processor" is by no means the only definition of those terms, you could have
#include <stdio.h>
#include <limits.h>
int main(void)
{
size_t proctype = sizeof(void *) * CHAR_BIT;
/* If you have a C99 library, or a version of printf
that understands it, you can print it with */
printf("proctype = %zu\n", proctype);
/* otherwise you need */
printf("proctype = %lu\n", (unsigned long)proctype);
return 0;
}
I have covered all this before.
The one programming problem that C certainly cannot handle is cleaning up the semantics of "32 or 64 bit processor", which has a number of meanings.
Also consider, for example, possibly having a C compiler on a PDP-8 with 12-bit words, a PDP=15 with 18 bit words, an IBM 7094 or PDP-10 with 36-bit words. It is unlikely that, on any meaning, any of these can be described as a 32-bit or 64-bit processor. The number of machines with word sizes such that they are not describable as 32-bit or 64-bit machines is very large. That you haven't encountered them doesn't matter.
.
- References:
- 32 or 64 bit processor info in C
- From: broeisi
- Re: 32 or 64 bit processor info in C
- From: Flash Gordon
- Re: 32 or 64 bit processor info in C
- From: broeisi
- Re: 32 or 64 bit processor info in C
- From: Martin Ambuhl
- Re: 32 or 64 bit processor info in C
- From: broeisi
- 32 or 64 bit processor info in C
- Prev by Date: Re: Reg: #define
- Next by Date: Re: GSoap
- Previous by thread: Re: 32 or 64 bit processor info in C
- Next by thread: Re: 32 or 64 bit processor info in C
- Index(es):
Relevant Pages
|