How to determine the number of digits of the operating system without sizeof
As shown in a post on the Forum
Http://topic.csdn.net/u/20110926/14/3cf3149d-6715-471d-9105-933d55e9c9ad.html
There is a solution:
# Include <stdio. h> # include <string. h> char Buf [17]; int main () {int * P = (int *)-1; sprintf (BUF, "% x", P ); printf ("system is % d bit. \ n ", strlen (BUF) * 4 );}
However, it is said that the 64-bit system does not work. No 64-bit system is used for verification ..
Or
Int x = 32767 + 1 ;//0x7fffIf (x <0) {printf ("16 \ n");} else {printf ("32 \ n ");}
And
You should know the addressing capability. Print an address at will, int * P, and then printf ("% d", P). For example, if the output is 7a3e, it is 16 bits, if it is ipv7a3e, It is a 32-bit
This statement
Someone posted the content on msdn.
In 64-bit windows, int and long are 32-bit values. ForProgramDo not assign the pointer to a 32-bit variable. On the 64-bit platform, the pointer is 64-bit. if the pointer is assigned to a 32-bit variable, the pointer value should be truncated. In 64-bit windows, size_t, time_t, and ptrdiff_t are 64-bit values. In Visual C ++ versions earlier than visual C ++ 2005 on a 32-bit Windows operating system, time_t is a 32-bit value. In Visual C ++ 2005 and later versions, time_t is a 64-bit integer by default. For more information, see time management.
So
# Define OS _bits (INT) (ptrdiff_t *) 0 + 1) <3)
This approach should also be feasible
In fact, it is difficult to have fixed answers to such questions, because sometimes we do not know whether the result is the number of digits of the compiler or the number of digits of the system, in addition, the results of different compilers may be different in systems with different digits.
We should just consider the various ideas.