In article <ehikci$l4s$1@news.cn99.com>,
Ye Dafeng <kobe082002@gmail.comwrote:
Quote:
>huangshan wrote:
Quote:
>can you give me a example ?
>>
>thanks
>>
>>
>
>char* getVoid()
>{
> char temp = 'c';
>
> return &temp;
>}
>
>in this example, the temp address may be used for other object. If you
>use it, you will get another result which you do not expect.
Right, as Victor mentioned, temp is not guaranteed to exist once
getVoid is over with. Therefore, to return its adress to be used
as if it still exists is asking for trouble. This is another facet
of something I term "good garbage" because it is something that
may appear to work, but use that pointer 10 minutes lates and
it may not be pointing at temp any longer but some other variable
which has taken its place, and so on.
--
Greg Comeau / 20 years of Comeauity! Intel Mac Port now in beta!
Comeau C/C++ ONLINE ==
http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?