The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Why not a segmentation fault?? lagigliaivan High Level Programming 22 05-21-2008 08:07 AM
Segmentation Fault compbug UNIX for Dummies Questions & Answers 3 04-21-2006 07:43 AM
segmentation fault wojtyla High Level Programming 3 02-19-2005 11:53 AM
Segmentation fault jshaulis AIX 1 06-01-2004 01:16 PM
segmentation fault omran High Level Programming 2 08-01-2003 05:19 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 11-24-2006
Registered User
 

Join Date: Nov 2006
Posts: 5
Question segmentation fault

ive written my code in C for implementation of a simple lexical analyser using singly linked list hence am making use of dynamic allocation,but when run in linux it gives a segmentation fault is it cause of the malloc function that ive made use of????any suggestions as to what i could do???
thank you!!

Last edited by rockgal; 12-02-2006 at 10:02 PM.
Reply With Quote
Forum Sponsor
  #2  
Old 11-25-2006
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 4,261
I can't tell what your problem is from here.
The first problem is to find where in your code the segfault occurs -
compile and run your code under a debugger (gdb)
Code:
gcc -g -o myfile myfile.c
gdb myfile
gdb > r  <command line arguments>
<segfault happens here>
ba
The ba command in gdb will show a stack trace. Please post it.
Reply With Quote
  #3  
Old 11-25-2006
Registered User
 

Join Date: Nov 2006
Posts: 5
Ya will do that & get back to you...
thanks

Last edited by rockgal; 12-02-2006 at 10:03 PM.
Reply With Quote
  #4  
Old 11-25-2006
reborg's Avatar
Administrator
 

Join Date: Mar 2005
Location: Ireland
Posts: 3,585
rockgal, please review the rules:


(9) Edit your posts if you see spelling or grammar errors (don't write in cyberchat or cyberpunk style). English only.
Reply With Quote
  #5  
Old 11-27-2006
Registered User
 

Join Date: Nov 2006
Posts: 5
I tried out these commands gdb >r <myfile> & gdb bt <myfile> on fedora 4.0
and this is what i got
bash: syntax error near unexpected token 'newline'
Am not sure of the syntax of the command but i picked up 'bt' from the man pages. I did try all possibilities and this is what i got for all of them...!
Please let me know if my command syntax is wrong or thats the error in my program and how can i debug it???
thank you,
rockgal

Last edited by rockgal; 12-02-2006 at 10:03 PM.
Reply With Quote
  #6  
Old 11-27-2006
andryk's Avatar
Registered User
 

Join Date: Sep 2003
Posts: 448
Quote:
gdb > r <command-line>
refers to gdb prompt typing r + optional command-lines
Seems like you are typing this in bash "gdb >r <myfile> & gdb bt <myfile>"
Reply With Quote
  #7  
Old 11-28-2006
Registered User
 

Join Date: Aug 2005
Location: Saskatchewan
Posts: 974
Crashing in linux, as in, doesn't crash in windows?

Windows lets you get away with a lot of stupid stuff sometimes, but only temporarily. Instead of crashing immediately as Linux does, it silently corrupts the heap, causing inexplicable errors in the future in code that has nothing to do with whatever your code did wrong.

It's frustrating, I know. It's only when I moved to linux did I find out how bad some of my code was!

P.S: "U" is not a word!
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
linux

Thread Tools
Display Modes




All times are GMT -7. The time now is 03:24 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0