nixCraft Linux Forum

nixCraft

Linux Tech Support Forum

what is dangling pointers under GCC?

This is a discussion on what is dangling pointers under GCC? within the Coding in General forums, part of the Development/Scripting category; Hi Anyone know what is dangling pointers? If possible give me some example… I’m using FreeBSD with GCC Thx...


Go Back   nixCraft Linux Forum > Development/Scripting > Coding in General

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 05-25-2005, 11:42 AM
Guest
 
Posts: n/a
Default what is dangling pointers under GCC?

Hi

Anyone know what is dangling pointers? If possible give me some example… I’m using FreeBSD with GCC

Thx
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-25-2005, 07:17 PM
rockdalinux's Avatar
Contributors
User
 
Join Date: May 2005
Location: Bangalore
My distro: RHEL, HP-UX, Solaris, FreeBSD, Ubuntu
Posts: 564
Rep Power: 7
rockdalinux is a jewel in the rough rockdalinux is a jewel in the rough rockdalinux is a jewel in the rough rockdalinux is a jewel in the rough
Default

Pointers that point to invalid addresses is called dangling pointers.

Some Examples that causes dangling pointers:
  • Casting arbitrary integers to pointers
    Adjusting pointers beyond the bounds of arrays
    Deallocating storage that one or more pointers still reference

C code/example of dangling pointers:
Code:
somefunc(){
x=(int *)malloc(sizeof(int));
...
free(x);
return (x); /* x is dangling pointer */
}
To avoid dangling pointers always assign NULL in C after freeing memory:
Code:
...
free(x);
x=NULL;
....
Reply With Quote
  #3 (permalink)  
Old 05-26-2005, 10:54 AM
Guest
 
Posts: n/a
Default

Thanks a lot

It is clear now...
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT +5.5. The time now is 04:28 AM.


Powered by vBulletin® Version 3.7.3 - Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36