I have tried the same on gcc and does not give any error here also . i
also tried to print the value of i the program while running the
program , i am not an expert , but i suspect the memory allocation after
*i=30  , is not changing , does that have anything to do with the
problem ??

Breakpoint 1, main () at doubt.c:5
5        {
Missing separate debuginfos, use: debuginfo-install glibc.i686
(gdb) print i ;
Invalid character ';' in expression.
(gdb) print i 
$1 = (int *) 0x8048450
(gdb) step
main () at doubt.c:7
7            i=(int *)malloc(1*sizeof(int));
(gdb) print i 
$2 = (int *) 0xbbddd0
(gdb) step
8            *i=30;
(gdb) print i 
$3 = (int *) 0x88c8008
(gdb) step
9            free(i); // freed the mem
(gdb) print i 
$4 = (int *) 0x88c8008
(gdb) step
10           *i=50; //  Tried to acces it again .. Ideally , it should fail .
But  it is not failing .. can any //one explain the reason.
(gdb) print i 
$5 = (int *) 0x88c8008
(gdb) step
11      }
(gdb) print i 
$6 = (int *) 0x88c8008
(gdb) step
0x00be55d6 in __libc_start_main () from /lib/libc.so.6
(gdb) print i 
No symbol "i" in current context.
(gdb) step
Single stepping until exit from function __libc_start_main, 
which has no line number information.

Program exited with code 010.
(gdb) print i 
No symbol "i" in current context.



On Tue, 2008-11-11 at 00:19 +0530, Gopi Krishna Komanduri wrote:
> Hi All,
>   I have a very basic query. I know that after deallocating memory for
> a pointer , when we try to access it , we will get access violation
> error. From top of my memory , even I tried it and worked on it. But
> now I dont know why but my code is working in wrong manner now. Can
> any one of you please suggest it please. I am using VisualStudio 2005
> compiler. on windows xp.
> 
> #include<stdio.h>
> #include<malloc.h>
> 
> void main()
> {
>     int *i;
>     i=(int *)malloc(1*sizeof(int));
>     *i=30;
>     free(i); // freed the mem
>     *i=50; //  Tried to acces it again .. Ideally , it should fail .
> But  it is not failing .. can any //one explain the reason.
> }
> 
> Thx,
> --Gopi
> 
> Connect with friends all over the world. Get Yahoo! India Messenger at
> http://in.messenger.yahoo.com/?wm=n/
> 
> [Non-text portions of this message have been removed]
> 
> 
> 
> 
>  
-- 
http://satish.playdrupal.com

Reply via email to