TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: CHRISTIAN S. PEDERSEN
from: ASHER DENSMORE-LYNN
date: 1997-07-25 12:58:00
subject: Conversion of pointer.

24 Jul 97 20:49, Christian S. Pedersen wrote to All:
 CP> Hello All.
 CP> Behold, a function which returns a pointer:
 CP> int* test()
 CP> {
 CP>     int i=5;
 CP>     return &i;
 CP> }
 CP> Why do I get a "Suspicious pointer conversion"-warning ? The functions
 CP> using this concept seems to work OK. Should I make them differently.
Think this through, Christian.
You're declaring a variable inside a function.
Now, you're pointing to that variable.
You've now left the function -- all automatic (think: local) variables are 
deinitalized. Poof -- they no longer exist.
BUT THE POINTER STILL POINTS TO IT.
Bad thing. Very bad thing. You're pointing to a location in memory that does 
not neccesarily contain -- well, anything. I don't even want to THINK about 
what'd happen if you tried to write to it.
Asher Densmore-Lynn 
... Debate is the death of conversation.
--- Squish v1.11
---------------
* Origin: Phaenix Rampant, 'Uhm... I hit it again!' (1:130/115)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.