In theory, you can have a C implementation where char
are 32 bits, and sizeof(char)
= sizeof(int)
= sizeof(long)
= 1, and probably sizeof(long long)
= 2; IIRC some experimental implementation of C in Common Lisp (or maybe SBCL only) is doing similar stuff. Sadly, I forgot the details.
In practice, better use <stdint.h>
giving int32_t
, int64_t
and an intptr_t
such that sizeof(intptr_t)
= sizeof(void*)
.
So the answer is no.
You might use <limits.h>
and INT_MAX
etc...
You could have a cross-compiler.... (e.g. compiling on a Linux x86-64 desktop for an 32 bits ARM android tablet with a cross GCC).
You might want to use things like autoconf. Read about GCC common predefined macros. Perhaps you want __LP64__
And you might have a Linux OS with 64 bits support on x86-64, but running in a chroot
-ed environment (or container à la docker) providing a 32 bits environment (with 32 bits libc, 32 bits compiler, etc...). This is actually useful (e.g. to test on a 64 bits Linux laptop that your app can be compiled and executed on 32 bits). See e.g. schroot. And most Linux x86-64 systems are able to run 32 bits x86 ELF binaries (at least if they are statically linked). BTW, on my Linux/Debian/x86-64 system gcc -m32
produces 32 bits object files and executables, but gcc -m64
or just gcc
gives 64 bits ...
On POSIX systems, to find out about your machine, use uname(2). On Linux, you can even read and parse /proc/cpuinfo
(and some other files under /proc/
, see proc(5)).
I know nothing about Windows. If you are using it, you should give Linux a try.