Author Topic: Program results are different for debug and run  (Read 5963 times)

Offline inl1ner

  • Single posting newcomer
  • *
  • Posts: 3
Program results are different for debug and run
« on: May 28, 2014, 10:44:14 pm »
Hi All,

I use CB 13:12 rev 9501 Build : Dec 27 2013 , 12:58:38 - wx2.8.12 (Windows, unicode) - 32 bits , SDK version 1.19.0 .

In a small project of about 500 lines of C code hits me the strange problem that the result is displayed entirely correct
in a console window in debug mode while in the run mode ( F11) the results are wrong.

The point is that a linked list of students with matriculation number, first name and last name is to create and is then
written with fprintf in a simple text file. Then the list is sorted by first name, also written to a file and then the same
with a sort by last name.

Finally, the list will be cleared from memory and read the file again sorted by enrollment number with fscanf.

When I debug the whole game with some breakpoints and check the list in the Watch Window in each of these cycles,
everything looks great and also the content of the stored files is correct. As soon as I run the code without the debugger
with Build and Run, the two sorts did not work and both by name sorted lists look exactly as the sorted list by matriculation
number. The three files created in accordance with the display of the console.

Can anyone give me a hint what causes this discrepancy between dubug and run mode?
Are there settings for the debugger that affect the runtime behavior (other than the time itself) :...

Regards
inl1ner

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13406
    • Travis build status
Re: Program results are different for debug and run
« Reply #1 on: May 28, 2014, 11:19:39 pm »
In a small project of about 500 lines of C code hits me the strange problem that the result is displayed entirely correct
in a console window in debug mode while in the run mode ( F11) the results are wrong.
99.99% you have uninitialized memory/variables somewhere. Or other similar memory problems.

Find a tool that checks for such problem or inspect you program carefully.

If you're using threads or some for of concurrency then you probably have a race somewhere.

p.s. this is not a C::B question...but a general programming one.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline inl1ner

  • Single posting newcomer
  • *
  • Posts: 3
Re: Program results are different for debug and run
« Reply #2 on: May 29, 2014, 11:08:35 pm »
@oBFusCATed

many thanks for your answer.

After all, did you busy with my problem. Ultimately, it was a mistake to have caused my almost non-existent C-skills, namely incorrect transfer of parameters to the function call. The sort was in fact not go through, but stopped immediately at the beginning because of the NULL pointer again, but why it was different when debugging ...

greetings
inl1ner

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13406
    • Travis build status
Re: Program results are different for debug and run
« Reply #3 on: May 29, 2014, 11:30:40 pm »
Sometimes there are differences in the allocators, stack behaviour, etc that masks such problems.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline inl1ner

  • Single posting newcomer
  • *
  • Posts: 3
Closed: Re: Program results are different for debug and run
« Reply #4 on: May 31, 2014, 01:54:52 pm »
I agree that this entry is closed.

Regards
inl1ner