In designing a new programming language, is it safe to assume that a C int and a pointer are the same size on the machine?
No, especially in 64 bit environments:
LP64 This covers *nix environments but the same is true in windows for LLP64.
no, but a pointer should be the same size as a intptr_t.
I believe the Linux Kernel passes pointers as unsigned long's. They are guaranteed to be at least the same size as a pointer :)
No, not at all. Many compilers do not have them as the same size.
No. A pointer may be larger or smaller than an integer in size. If you need to pass a pointer as an integer for some reason (like performing integer, rather than pointer, arithmetic), they are guaranteed to fit into an intptr_t.
They are not guaranteed to fit into a size_t as suggested in another answer, but in practice it is unlikely that they won't, since the largest addressable size is usually equal to the largest addressable address.
No; on my MacOS X 10.6.5. machine, an int
is 32 bits and a pointer is 64 bits by default.
If you need an integer that's the right size to hold a pointer too, use #include <inttypes.h>
(or <stdint.h>
) and uintptr_t
- assuming you have C99 support, or can simulate it.