Re: [ilugd] Re: strcpy local variable in c

2004-03-04 Thread Arindam Dey
On Thu, 2004-03-04 at 15:38, Vikas Upadhyay wrote: From: Abhijit Menon-Sen [EMAIL PROTECTED] At 2004-03-04 12:24:25 +0530, [EMAIL PROTECTED] wrote: According to me, as we have string as local variable, it should vanish. But, i am still able to return and print the string hello

Re: [ilugd] Re: strcpy local variable in c

2004-03-04 Thread Arindam Dey
On Thu, 2004-03-04 at 16:07, Arindam Dey wrote: Try adding these two statements and changing your foo() function char * foo() { char string[200]; char * ptr=NULL; strcpy(string,hello world); printf(StrAddr=%x\n,string[0]); // Print address of the starting

[ilugd] Re: strcpy local variable in c

2004-03-04 Thread Abhijit Menon-Sen
At 2004-03-04 16:07:16 +0800, [EMAIL PROTECTED] wrote: Very true when the function returns the stack is emptied and all local variables are deleted. That's not true, and it's a very misleading way of thinking about this situation. Yes, automatic variables (as C calls them) are allocated on the

[ilugd] Re: strcpy local variable in c

2004-03-04 Thread Abhijit Menon-Sen
At 2004-03-04 13:22:02 +0530, [EMAIL PROTECTED] wrote: *No* valid assumptions can be made with respect to undefined behaviour. You cannot even expect it to not work. Oh, and just as an illustration of what this means, according to the C standard, the behaviour of #pragma is implementation

Re: [ilugd] Re: strcpy local variable in c

2004-03-04 Thread Vikas Upadhyay
Very true when the function returns the stack is emptied and all local variables are deleted. But the pointer is made on the heap not the stack!So you will have to delete the pointer manually. You are taking control away from the compiler and telling it that you are implementing it manually

Re: [ilugd] Re: strcpy local variable in c

2004-03-04 Thread Arindam Dey
On Thu, 2004-03-04 at 16:56, Abhijit Menon-Sen wrote: [snipped some excellent discourse by AMS] Thank you very much for clearing that up. I was pretty mistaken about the stack and heap thing. I had totally forgotten about the malloc thing have been using new and delete for quite a while now :-).

RE: [ilugd] Re: strcpy local variable in c

2004-03-04 Thread D.Venkatasubramanian, Noida
-Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] lhi.org]On Behalf Of Vikas Upadhyay Sent: Thursday, March 04, 2004 2:41 PM To: The Linux-Delhi mailing list Subject: Re: [ilugd] Re: strcpy local variable in c -- snip Still frnds, I am not very clear

[ilugd] Re: strcpy local variable in c

2004-03-03 Thread Abhijit Menon-Sen
At 2004-03-04 12:24:25 +0530, [EMAIL PROTECTED] wrote: According to me, as we have string as local variable, it should vanish. But, i am still able to return and print the string hello world. Returning a pointer to local variables is undefined; that is, there is no guarantee whatsoever about

Re: [ilugd] Re: strcpy local variable in c

2004-03-03 Thread Vikas Upadhyay
From: Abhijit Menon-Sen [EMAIL PROTECTED] At 2004-03-04 12:24:25 +0530, [EMAIL PROTECTED] wrote: According to me, as we have string as local variable, it should vanish. But, i am still able to return and print the string hello world. Returning a pointer to local variables is undefined;

[ilugd] Re: strcpy local variable in c

2004-03-03 Thread Abhijit Menon-Sen
At 2004-03-04 13:08:14 +0530, [EMAIL PROTECTED] wrote: By vanish I mean, function gone it's data gone. I know what you mean. It's a common expectation, but as I said, there is no guarantee that any such thing will happen. *No* valid assumptions can be made with respect to undefined behaviour.