Thread: Seg fault in strange place

  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    119

    Seg fault in strange place

    I ran my program against gdb to track down a segmentation fault. It's happening in a classes print method. When I attempt to print an ID number of an object being stored within that object, it gives me a segmentation fault...I'm just printing one of the parameters of that object, which just so happen to be an object and have it's own parameters. Does this mean my object that's a parameter was never created? I don't see why printing an objects variable is bad, unless there's nothing there...?

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    There can be lots of potential problems. Showing the code (or snippets of it) would probably help. If you can whittle it down to a small but complete example that still shows the problem that would be even better.

    Is the member object allocated dynamically? Was the instance of the main object created dynamically? Are there any arrays or other containers nearby that you might have accessed illegally?

    Is this the same segmentation fault as last time?

  3. #3
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by John_L View Post
    I ran my program against gdb to track down a segmentation fault. It's happening in a classes print method. When I attempt to print an ID number of an object being stored within that object, it gives me a segmentation fault...I'm just printing one of the parameters of that object, which just so happen to be an object and have it's own parameters. Does this mean my object that's a parameter was never created? I don't see why printing an objects variable is bad, unless there's nothing there...?
    Probably you are calling through a pointer or reference which is bogus. Possibly null. In the debugger, type "print this" and see what you get. If it's not zero, type "print *this" and see what you get.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Seg Fault -- Plz Help Quick
    By djwicks in forum C Programming
    Replies: 1
    Last Post: 04-10-2005, 09:08 AM
  2. Pointer To Functions = Seg Fault
    By misplaced in forum C++ Programming
    Replies: 3
    Last Post: 04-05-2005, 08:03 AM
  3. strange segmentation fault error!
    By jayjay in forum Linux Programming
    Replies: 1
    Last Post: 10-20-2003, 03:25 PM
  4. Seg Fault Problem
    By ChazWest in forum C++ Programming
    Replies: 2
    Last Post: 04-18-2002, 03:24 PM
  5. seg fault on unix platform
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 12-08-2001, 12:04 PM