Home > OS >  C Heap Environment variable
C Heap Environment variable

Time:11-21

Is there an environment variable in c which stores the heap word size, or at least a variable which stores the type of system ? For example in 64 bit system would be 8(bytes) and in 32 bit would be 4(bytes)

CodePudding user response:

Note that 64 bit systems can execute 32 bit binaries, in this case, sizeof(void *), sizeof(int), ... will be 4, even on 64 bit system.

You can get some additional mileage using the uname system call (see uname -m). For Intel, it will be x86_64 (64), or i686 (for 32). If you need a solution for Intel only, this can work. You can extend this to other processor (arm, etc.) but you will need to code each platform that you code may run on. See "machine" in: https://man7.org/linux/man-pages/man2/uname.2.html

To make things more complex, you might be running under 32 bit operating system, which runs under 64 bit processor (or some virtualized environment). In those cases, uname will report on the operating system, not on the processor. Not clear which one you are looking for.

  • Related