What is the range of illegle memory addresses?

Paul Smith paul@mad-scientist.net
Tue May 18 21:49:15 GMT 2021


On Tue, 2021-05-18 at 16:35 -0500, Peng Yu via Gcc-help wrote:
> So, to write a portable C program, no values other than NULL should
> be used as an invalid memory address?

If by "invalid" you mean, a value that is guaranteed by the standard to
never be the address of any valid memory location, then correct: 0 and
NULL, which are the same thing in a pointer context, are the only ones
(0 in a pointer context is understood to mean "invalid pointer value"
and if you are working on some architecture where "invalid pointer
value" is NOT the same bit pattern as integer 0, then it's the
responsibility of the _compiler_ to convert the "0" token in your code
to whatever bit pattern means "invalid pointer" on that system--so in
your code you always write 0 regardless of the underlying hardware
requirements).




More information about the Gcc-help mailing list