Exforsys

Online Training

To make Dangling pointer

This is a discussion on To make Dangling pointer within the C and C++ forums, part of the Programming Talk category; I have a portion of extract of my code as below struct node *test(int inp) { struct node *t; t = (...


Go Back   Exforsys > Programming Talk > C and C++

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-15-2007, 07:31 PM
Senior Member
 
Join Date: Apr 2006
Posts: 139
Ralph is on a distinguished road
To make Dangling pointer

I have a portion of extract of my code as below

struct node *test(int inp)
{
struct node *t;
t = (struct node *) malloc(sizeof(struct node));
.........
........
return t;
}

I want to make the pointer t as dangling pointer .Someone suggests me a way for achieving this.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 05-16-2007, 04:33 PM
Senior Member
 
Join Date: Apr 2006
Posts: 145
Rahulbatra is on a distinguished road
Your t is already a dangling pointer because t is defined within the scope your function test and when it is returned it results in pointing to a object which does not exists thus resulting in dangling pointers.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 05-16-2007, 04:38 PM
Senior Member
 
Join Date: Apr 2006
Posts: 139
Ralph is on a distinguished road
But my program did not give any error or warning and neither crashed. It is amazing being used as dangling pointers how my program worked. Kindly explain me on this.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 05-18-2007, 04:03 PM
Senior Member
 
Join Date: Apr 2006
Posts: 145
Rahulbatra is on a distinguished road
It is not essential or mandatory that your program should crash if you have used dangling pointers. But you would get program crash if you use automatic variables in that memory defined in your C program and try to use that after usage of dangling pointers in your program. Make a try in this way and you would see your program crash.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools

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


Similar Threads

Thread Thread Starter Forum Replies Last Post
comp.lang.c Answers (Abridged) to Frequently Asked Questions (FAQ) Steve Summit Tech FAQ 0 06-15-2004 07:00 AM
comp.lang.c Answers (Abridged) to Frequently Asked Questions (FAQ) Steve Summit Tech FAQ 0 06-01-2004 07:01 AM
comp.lang.c Answers to Frequently Asked Questions (FAQ List) Steve Summit Tech FAQ 0 06-01-2004 07:00 AM
comp.lang.c Answers (Abridged) to Frequently Asked Questions (FAQ) Steve Summit Tech FAQ 0 05-15-2004 07:00 AM
Solaris x86 FAQ 2/2 Dan Anderson Tech FAQ 0 04-27-2004 08:24 PM


All times are GMT -4. The time now is 12:41 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0
Copyright 2004 - 2007 Exforsys Inc. All rights reserved.