As title says, is there any elegant and safe way to determine if architecture is 32bit or 64bit. By elegant, you can think of precise, correct, short, clean, and smart way.
short answer: no
long answer: it depends on too many OS/compiler combinations. For example at runtime, on linux you can query the proc filesystem whereas on windows you can query the register.
You can prove that the compiler that are being used for compilation has a 32/64 bits target using something like:
bool is_32bit() {
return sizeof(int *) == 4;
}
bool is_64bit() {
return sizeof(int *) == 8;
}
this could works under few assumptions (e.g. it works at runtime). You can search for compile-time #define
for your platform but it is a well-known mess.