![]() |
|
#1
|
|||
|
|||
Baffling Segmentation Fault...So I am just working on a MD program but either way I am having a not so fun time making it work (properly).
So it starts out normally and I call in several modules. CPP / C++ / C Code:
So the values npart_def etc. come from the setup.h and they are defined properly and work, no issues here.. Then these variables are passed to the another module, from the main routine it looks like.. CPP / C++ / C Code:
Then in the Getinitials function it looks like.. CPP / C++ / C Code:
and this works fine also.. then in the main routine (**Placeholder**) CPP / C++ / C Code:
And Initout function looks like CPP / C++ / C Code:
What happens though, is when the Getinitials is called, if I leave all the values and just hit enter or enter the same number, the program runs fine. However, if I change any of the numbers (I don't change npart, because it isn't really designed to be changed yet) then I get a segmentation fault when it tries to open the log.dat file.. So it seems weird that it only happens when I change the values otherwise it works, baffling.. Also, if I change the Initout function to be where I said **Placeholder** then I don't get a segmentation fault, but later on when I print values they all show up as nan. Any help is appreciated... I am no professional programmer, and C++ was never my game.. I shoulda been a plumber ![]() |
|||
|
#2
|
|||
|
|||
Re: Baffling Segmentation Fault...Quote:
Are you, perhaps, using npart = 2? If so, then the following leads to undefined behavior since, in C and C++, array index values start at zero, not one. CPP / C++ / C Code:
Same for y and z. Undefined behavior can manifest itself in different ways, and sometimes it depends on various conditions at run time. (Like sometimes the program crashes and sometimes not. Stuff like that.) Regards, Dave |
|
#3
|
|||
|
|||
Re: Baffling Segmentation Fault...One-off problems like davekw7x mentions are very common, & can lead to nasty, but subtle results.
Likewise, I see no error checking on a whole lot of heapspace allocations. What kind of heapspace requirements do you have & does the platform used support these needs? |
|
#4
|
|||
|
|||
Re: Baffling Segmentation Fault...Hey, thanks, that worked.. I think. Just got to see if I can get it working again after I mashed it up something fierce. How i had it set up is the loops for 1-2 not 0-1.. If I use:
x = new double[2] does that define x[0] and x[1] as in 2 spots, or does it define x[0], x[1], x[2] as in 0 to 2? Thanks again for your time, I appreciate it |
|
#5
|
|||
|
|||
Re: Baffling Segmentation Fault...Quote:
|
|
#6
|
|||
|
|||
Re: Baffling Segmentation Fault...This is basic operation in C/C++ and often lead to common bug in program.
|
|
#7
|
|||
|
|||
Re: Baffling Segmentation Fault...Yea totally, I managed to fix most of my damage last night; thanks a bunch guys you saved me a week of banging my head on the table!
![]() |
|
#8
|
|||
|
|||
Re: Baffling Segmentation Fault...Quote:
I used to do this all of the time, and my mom was afraid that I was going to damage the table, so she came up with a Better Plan. See attachment. I taped this onto the outside wall of the little brick "house behind the house" and she was much happier. (Not quite so happy, of course, when she was inside the little house, but it still saved lots of wear and tear on the table.) Regards, Dave Last edited by davekw7x : 04-Jun-2008 at 09:56.
|
Recent GIDBlog
Toyota - 2009 May Promotion by Nihal
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| I have a segmentation fault in my project | takachi | C++ Forum | 6 | 09-Mar-2008 23:30 |
| Find the Segmentation Fault | jlwelch | C Programming Language | 3 | 10-Oct-2006 11:16 |
| My Bane - The Segmentation Fault | DCOM | C Programming Language | 6 | 08-Feb-2005 23:58 |
| segmentation fault in c++ | rushman8282 | C++ Forum | 2 | 26-Jan-2005 04:38 |
| child pid xxx exit signal Segmentation fault (11) | bezak | Apache Web Server Forum | 1 | 24-Nov-2003 10:18 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The