Re: How to determine if running on a 32 or 64 bits kernel ?



laurent.charmet@xxxxxxxxx wrote:
I'm looking for an API or whatever to determine if kernel/os is 32 or
64 bits. It must be dynamic, because my binary can be compiled on a
machine and run on another. So sizeof(void*) is useless since it give
4 if my program was compiled on a 32 bits linux, even if I run it on a
64 bits.

I do not find information in /proc nor in sysconf, sysinfo etc ...

The only solution, but very crappy is to make a popen of "file -b /usr/
bin/file" and search for string "64" ...

uname -a

sizeof (void*) will give you the size of a pointer to nothing ;-)

A program compiled on 32 bit and linked with 32 bit libs will always be
32 bit... Sizeof is usually evaluated during compile time.
.



Relevant Pages

  • Re: How do you do this?
    ... useless, but I wrote it to illustrate something that puzzles me: ... You are missing the fact that Python is designed to be an interpreted ... lexical bindings are always resolvable at compile time. ...
    (comp.lang.scheme)
  • Re: [RFC] [PATCH] Fix b43 driver build for arm
    ... I can't see why we would want to check _anything_ of the target stuff ... I can compile an ARM kernel on any machine I want. ... So it seems what this check _wants_ to compare the sizeof the structure ...
    (Linux-Kernel)
  • Re: [RFC] [PATCH] Fix b43 driver build for arm
    ... I can't see why we would want to check _anything_ of the target stuff ... I can compile an ARM kernel on any machine I want. ... So it seems what this check _wants_ to compare the sizeof the structure ...
    (Linux-Kernel)
  • Re: How to correct the code segment?????????????
    ... It suggests to the naive programmer that there are variable sized ... The result of sizeof is (in ... You can't be sure that it will compile to the same code, ... so sum_hist is an array of elementStruct (apparently a typedef; ...
    (comp.lang.c)
  • Re: pointer subtraction and sizeof
    ... Somebody pointed a link that says that sizeof may calculated ... word size boxes but it can pass compile and can run but maybe the result is ... I was thinking of one more scenario where this may fail, ... Shouldn't the addition of 1 to the obj pointer fail on this machine and ...
    (comp.lang.c)