Re: 32 or 64 bit processor info in C



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.


.



Relevant Pages

  • Re: address of a statement in C
    ... C doesn't even require that an implementation have a program counter. ... the old drum machines, like that IIRC in The Story of Mel, but some ... had actually been executed in an order consistent with the abstract ... label, and goto that pointer. ...
    (comp.lang.c)
  • Re: Consciousness: whats the problem?
    ... is a sequence of symbols taken from a finite symbol set. ... grant that the term "information" has multiple meanings, ... I grasp that level of abstraction. ... I build machines. ...
    (comp.ai.philosophy)
  • Re: void pointers & void function pointers
    ... > void; ... try to coerce a pointer of one class to a pointer of the other, ... Machines that maintain "permission bits" on regions of memory ...
    (comp.lang.c)
  • Re: Integers on 64-bit machines
    ... thought a bit about 64-bit machines and wanted to ask: ... pointers, e.g., pointer arithmetic), the main integer type should have ... It causes lots of portability bugs; ... M. Anton Ertl ...
    (comp.compilers)
  • Re: porting problems encountered
    ... We are adding 15 to myP, an integer, not p, the pointer. ... bit machines are fine with fetching 64 bit values from 32 bit bounded ... they like to fetch 64 bit values from addresses that end in 0 ... understanding THAT requires understanding what the hardware is doing. ...
    (comp.os.vms)