Question about pointer

Chris Torek torek at elf.ee.lbl.gov
Sat Mar 2 11:45:36 AEST 1991


In article <2488 at njitgw.njit.edu> yxz1684 at hertz.njit.edu (Ying Zhu ee) writes:
>The following is a small program from "Mastering C pointers" by Robert J.
>Traister. [example deleted] ... Since the r[100] is an automatic variable,
>after calling the "combine" the r[100] will be deallocated [and] p will
>point to an unsafe place.

Correct.

If the example in this book appears exactly as shown in
<2488 at njitgw.njit.edu>, I would suggest either discarding the book
entirely (reselling it merely pushes the bogus information on someone
else) or---if this is atypical, and merely one mistake out of a great
deal of correct code---advising the author and/or publisher, and
marking the example in the book to note its error or repair it.
(One `static' will repair this particular sample, for instance.)

Note that the only excuse these days for buggy examples is when the
publisher do their own re-typesetting, since book examples should
be typeset by direct insertion of working code into the typesetting
system.

There are many C books available these days, and a large fraction of
them are inexcusably bad.  Do not trust any single source (except
perhaps a copy of the ANSI C standard X3.159-1989).
-- 
In-Real-Life: Chris Torek, Lawrence Berkeley Lab EE div (+1 415 486 5427)
Berkeley, CA		Domain:	torek at ee.lbl.gov



More information about the Comp.lang.c mailing list