Scoping question in C

Peter plp-ysDPMY98cNQDDBjDh4tngg at public.gmane.org
Fri Jun 10 05:55:35 UTC 2005


On Thu, 9 Jun 2005, William Park wrote:

> I have question regarding scope of static string inside C function.
> Suppose I have
>
>    char *x;
>
>    int func ()
>    {
> 	x = "something";
> 	return (1);
>    }
>
> where 'x' is global variable being used elsewhere.  Can I use 'x' after
> func() exits?  That is, is 'x' still pointing to string "something"?

Yes, the literal string is allocated as static initialised data by the 
compiler at compile time.

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