You edited your question halfway through, in a way that changed its interpretation considerably. I'm going to answer both versions.
I want to know whether there is a guarantee that memory address is a positive integer
In C and C++, at least, a memory address is a memory address -- it is not necessarily an integer. In these languages, conversions between memory addresses (pointers) and integers are problematic, they require explicit casts, and they are not always guaranteed to work. However, if we do think of memory addresses as being integers, we invariably think of them as being unsigned integers, meaning that they simply can't be negative, on pretty much any platform.
I want to know whether there is a guarantee that memory address is a positive integer, including zero, in intptr_t
Aha. Very different question. intptr_t
is a signed type, so now what we want to know is, basically, are there any addresses in the "top half" of the address space, meaning that they have their high-order (most significant) bit set, meaning that they're interpreted as negative numbers if we treat them as a signed type?
When I first learned C, on the 16-bit PDP-11, the stack was at the top of the address space, starting at address 0xffff
, or -1, so yes, I saw lots of "negative" addresses, generally any stack address. (In those days we didn't have intptr_t
, but we did have addresses that looked negative if we went and treated them as signed integers.)
When Unix was first ported to the 32-bit VAX, and AFAIK for most/all 32-bit versions of Unix and Linux since then, user memory is restricted to the "bottom half" of the virtual memory address space, while the OS itself is mapped into the top half. So on those platforms, it turns out that user addresses will always look positive, which I guess is what you were asking about.
I don't know how Windows does things, and I don't know how things are typically laid out on modern, 64-bit OS's (much less when you've got an OS that's set up to support either 32-bit or 64-bit programs).
So I can't really help you fill in your table. Certainly there is no guarantee that a user address will always be positive when converted to intptr_t
. If you were hoping for such a guarantee, if you're thinking of writing a program which makes use of it, I would strongly encourage you to reconsider, if at all possible.
(Over the years, various "clever" programs for various "clever" reasons have tried to usurp one or more bits of a pointer variable, to use as flags for their own purposes, knowing that the bits Just Happened to be insignificant for actual pointer addresses that day. Though these programs may have achieved short-term performance gains, in my experience these tricks have always come to ruin in the end. I'd avoid them like the plague.)