Page 1 of 1
segmentation fault
Posted: Sun Feb 10, 2008 3:56 pm
by bloodhound23
I'm using a 64 bit system with Ubuntu. For every program I write that does anything more than
printf("name of program + copyright\n");
when I run it the konsole always says : "core dump segmentation fault"
or something like that , what could be the problem
Posted: Sun Feb 10, 2008 4:17 pm
by Brynet-Inc
I suppose the real question is.. what "more" are you doing after the printf?
Seriously man,
http://catb.org/~esr/faqs/smart-questions.html
Posted: Sun Feb 10, 2008 10:53 pm
by Pyrofan1
i remember the good old days when i programmed on windows and it accepted code like this
then i switched to linux and it segfault'd
Posted: Sun Feb 10, 2008 11:50 pm
by blound
c needs to be pointing somewhere valid....
Coping with Segmentation faluts
Posted: Mon Feb 11, 2008 1:48 am
by DeletedAccount
Coping up with segmentation faults
-----------------------------------------
You should learn how to use gdb properly ...
when compiling use the g flag .. eg gcc -g <urfile> -o<outputfile>
The run ur program in gdb ... eg gdb outputfile ...
at the gdb prompt use break <line no or func name > to use breakpoints
... use next and step to go through your code ... up and down etc for going up and down frames ... use print <variable name > to view variables in gdb prompt ..use list view source file etc .... There is more to gdb than this ... i just gave a quick summary ... use gdb effectively to sqat out your bugs
Posted: Mon Feb 11, 2008 1:56 am
by DeletedAccount
Pyrofan1 Posted: Mon Feb 11, 2008 4:53 am Post subject:
i remember the good old days when i programmed on windows and it accepted code like this Code:
char *c;
gets(c);
then i switched to linux and it segfault'd
It should segfault for your program's and your good .... When you declare a pointer like that it is pointing to a random address ... It will seg fault in windows also ... but you may be able to run it in dos using turbo C or some legacy compilers ... you should always use malloc before using gets(c) .... You have made a conceptually erraneous statement ....
Posted: Mon Feb 11, 2008 2:28 am
by Solar
Pyrofan1 wrote:i remember the good old days when i programmed on windows and it accepted code like this [...] then i switched to linux and it segfault'd
Means you
still don't run your compiler with proper warnings enabled, or you would have caught that problem long before it segfaults.
Posted: Mon Feb 11, 2008 4:19 pm
by Pyrofan1
*to all those who replied to my post telling me that i need the pointer to point somewhere, re-read the post and notice how i was talking in the past.