This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: malloc attributes and realloc
Bruce Korb <bkorb@veritas.com> writes:
> That's nice. Were there a compiler that were to take that clause
> and use it to destroy the semantics of a program, I would expect
> and actually hope that compiler would disappear and never see the
> light of day again.
There are compilers that do indeed trap and throw errors if you ever use
the value of a pointer to an object that has been freed in any way
whatsoever. Some people find them extremely valuable for error-checking.
However, they mostly only come up during discussions of this portion of
the standard and don't seem to be widely used.
For whatever it's worth, we're now treading into territory that's covered
in the comp.lang.c FAQ and which is rehashed in the newsgroup on a
depressingly consistent basis. To quote the FAQ:
A pointer value which has been freed is, strictly speaking, invalid,
and any use of it, even if is not dereferenced can theoretically lead
to trouble, though as a quality of implementation issue, most
implementations will probably not go out of their way to generate
exceptions for innocuous uses of invalid pointers.
References: ANSI Sec. 4.10.3
ISO Sec. 7.10.3
Rationale Sec. 3.2.2.3
You can find lots of instances of this discussion in Google Groups.
--
Russ Allbery (rra@stanford.edu) <http://www.eyrie.org/~eagle/>