String help!

Michiel B. Huisjes huisjes at ark.UUCP
Sun Feb 24 22:46:52 AEST 1985


In article <929 at ukma.UUCP> david at ukma.UUCP (David Herron, NPR Lover) writes:
>In article <8257 at watarts.UUCP> upen at watarts.UUCP (Ue-Li Pen) writes:
>> Is it allowed & portable to use the construct:
>> char* foo(){
>> return("foobar");    
>> }
>> This would hopefully return a pointer to the string "foobar"..
>
>Yes it does....However it is a pointer to a STATIC data area.
>So it wouldn't be a good idea to change the contents of the string.
>-- 
>-:--:--:--:--:--:--:--:--:--:--:--:--:--:--:--:--:--:--:--:--:--:--:--:-
>-:-David Herron;

David Herron is right, except for the fact that you are allowed to
change the contents of the string as long as you don't change the 
length of it!
So you are allowed to say:

main()
{
	char *ptr;
	char *foo();

	ptr = foo();
	strcpy( ptr, "barfoo" );
	.....
}
-- 

			Michiel Huisjes.
			{seismo|decvax|philabs}!mcvax!vu44!ark!huisjes



More information about the Comp.lang.c mailing list