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)
|