Disappearing Bug

This is a discussion on Disappearing Bug within the C++ Programming forums, part of the General Programming Boards category; hi all, Im new to the forum. so i get this assignment and am still baffled as to how i ...

  1. #1
    Registered User
    Join Date
    Aug 2009
    Posts
    1

    Disappearing Bug

    hi all,

    Im new to the forum. so i get this assignment and am still baffled as to how i should go about it. Ive googled it but to no avail. anyone have any ideas or can point me to the right direction please. Thanks. The question is as follows:

    A programmer was debugging her program written in a procedural language (c,pascal). Trying to locate a baffling bug , the programmer added a series of write statements which printed out the values of relevant program variables. To her surprise , the bug seemed to vanish and now the program executed to the end without any errors. However , when the write statements were removed, the bug reappeared and the program failed again! Note that the write stataements did not modify any of the variables in the program, the machine and the compiler worked OK, and the external facters (say solar, wind) had no effect whatsoever. The poor programmer was very frustrated.
    Explain how the disappearing bug was possible. Give an example program, show the contents of the activation stack at the relevant points of execution and describe the results of the actions with and without the write statements.
    thanks in advance

  2. #2
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,171
    Google "undefined bahaviour", "stack corruption".

  3. #3
    The larch
    Join Date
    May 2006
    Posts
    3,573
    I think this is some kind of puzzle and the solution should apply to all procedural languages.

    No idea, someone has posted the same question here, so lets hope someone clever posts the answer.

    Was the program multi-threaded?
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  4. #4
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    I've had this happen in my early days of C when a printf() would actually hide a previous corruption in a variable. The only thing I came up with is that somehow the printf() corrected the stack issue and didn't 'fix' the error but did cause the program not to crash. Just b/c a bug does not 'crash' does not mean that it won't bite you later. I have not experience this in quite some time although from time to time I do come across some oddities while debugging where the debug CRT corrects an issue. Sometimes the bug does not show up until I compile in release which by that time means it will be very hard to find the bug.

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,485
    A concrete example of how printf() can mess with the results.
    what's with gcc? - C++
    Though it takes about 20 posts to get to the bottom of it.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. gaks bug?
    By Yarin in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 08-31-2008, 02:47 PM
  2. Debugging a rare / unreproducible bug..
    By g4j31a5 in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 08-05-2008, 12:56 PM
  3. ATL bug of CComPtr?
    By George2 in forum Windows Programming
    Replies: 6
    Last Post: 04-07-2008, 07:52 AM
  4. Fixing bug in Quake 2 Engine!
    By hajas in forum Game Programming
    Replies: 4
    Last Post: 06-22-2007, 10:12 AM
  5. wierdest (annoying) C++ bug
    By phantom in forum C++ Programming
    Replies: 3
    Last Post: 10-20-2001, 08:12 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21