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
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
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
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
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
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 :-).
-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
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
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;
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.
10 matches
Mail list logo