What is the range of illegle memory addresses?
Tue May 18 21:35:55 GMT 2021
So, to write a portable C program, no values other than NULL should be
used as an invalid memory address?
On 5/18/21, Peter Bergner <firstname.lastname@example.org> wrote:
> On 5/18/21 10:55 AM, Peng Yu via Gcc-help wrote:
>> NULL (0) is a commonly used value for an invalid memory address. I
>> also see -1 is used for an illegal memory address.
>> Besides those values, I'd suspect that other values that are close to
>> 0 (both negatives and positives) won't appear in real programs.
>> Is there a limit on the safe range that can be assumed to not be used
>> by user level code as valid addresses?
> There is no such list that defines which virtual addresses are valid and
> are not. It depends on your OS, target, system config, etc. I've heard of
> some OS systems where 0 was ok to access and NULL was defined to be some
> non-zero value.
> Also, -1 is sometimes valid too. If you're running on a ppc64 (ie,
> Linux kernel and execute a 32-bit application and your system has enough
> the kernel will give you the full 4G virtual address space to your
More information about the Gcc-help