Scoping question in C

pking123-rieW9WUcm8FFJ04o6PK0Fg at public.gmane.org pking123-rieW9WUcm8FFJ04o6PK0Fg at public.gmane.org
Fri Jun 10 00:36:16 UTC 2005


> I have question regarding scope of static string inside C function.
> Suppose I have
> 
>     char *x;
> 
>     int func ()
>     {
>  x = "something";
>  return (1);
>     }
> 

You can test this out yourself with this code, defining a main() and 
printf'ing the result. On Cygwin, I get nothing (2 carriage returns).

> where 'x' is global variable being used elsewhere.  Can I use 'x'
> after func() exits?  That is, is 'x' still pointing to string

Well, you can *use* x, but I don't think it will have that value. But 
on my GCC compiler, I gave x an old value, which got clobbered and 
replaced with an empty string.

> "something"?
> 
> -- 
> William Park <opengeometry-FFYn/CNdgSA at public.gmane.org>, Toronto, Canada
> ThinFlash: Linux thin-client on USB key (flash) drive
>     http://home.eol.ca/~parkw/thinflash.html
> --
> 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
> 
> 
> __________ NOD32 1.1135 (20050609) Information __________
> 
> This message was checked by NOD32 antivirus system.
> http://www.nod32.com
> 
> 


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