Scoping question in C

Kevin Cozens kcozens-qazKcTl6WRFWk0Htik3J/w at public.gmane.org
Fri Jun 10 15:17:33 UTC 2005


William Park wrote:

>I did try it, and got what Henry and others said.  But, I just wanted to
>make sure that data access is legal.  Because, sometimes, I could access
>data pointed to by a dangling pointer for a while, before I get
>segfault.
>  
>
You will be in serious danger of getting a seg fault if 'char *x' was 
only declared inside func() and returned the pointer and you then tried 
to use this pointer outside of func(). You will also have problems when 
you continue to use pointers to memory that was allocated via (m)alloc() 
after it has been freed. These situations don't apply in your example 
since the variable x was declared outside of any function.

-- 
Cheers!

Kevin.  (http://www.interlog.com/~kcozens/)

Owner of Elecraft K2 #2172        |"What are we going to do today, Borg?"
E-mail:kcozens at interlog dot com|"Same thing we always do, Pinkutus:
Packet:ve3syb at ve3yra.#con.on.ca.na|  Try to assimilate the world!"
#include <disclaimer/favourite>   |              -Pinkutus & the Borg

--
The Toronto Linux Users Group.      Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml





More information about the Legacy mailing list