Thread: Why my code works only in debug mode?

  1. #1
    Registered User
    Join Date
    Jun 2007
    Posts
    12

    Question Why my code works only in debug mode?

    I wrote a c++ code using Microsoft visual c++. Now I have some weird problems

    I wrote the code on computer A, and runs well.

    Then I cope it to computer B. The source code can be compiled, but when I try to run it, it just stoped there, and did not show any error, and the CPU rate is 100%. However, If I open the project and press F5, the code could run in Debug mode.

    Actually, I also tried to run it on computer C. There is not Microsoft c++ on it, so I coped the missing library files to the local directory, and the code runs for a while, and stopped again, just like what happend to computer B.


    Can anybody give me some suggestions? why the code acts differently on different computers? and why it only runs in debug mode on computer B? This problem really drives me crazy.

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    the debug and release modes have some differencies - you can google for the full list...

    One of the most common problems - debug mode initializes all vars to 0, release mode - leaves garbage in all not explicetely initialized variables.

    Check that you always initialize variables before first use.

    PS. You can compile Release mode with Debug info check box on - and try to debug this version, sometimes it can show you the release only problem
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  3. #3
    Registered User
    Join Date
    May 2007
    Posts
    13
    Oh, I never knew that! Thanks for the enlightenment, vart!

  4. #4
    Registered User
    Join Date
    Jun 2007
    Posts
    12
    Thank you, I solved this problem.

    I used an array in my code, such as Array[i]. I initialzed the array for i= 0 to 3, but I used Array[4] by mistake. I guess in the debug mode, the Array[4] is ininitalized as 0 by compiler, but not so when you run the exe directly, and this mistake caused a endless loop in the code, and this is why the CPU rate is 100%, and the program got stuck without any error message.

    I just tryed to add some print out messages for each functions, and located the mistake that I made.

    There is still some other error happening to the program after running for about half and hour, I'll try to figure it out

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. True ASM vs. Fake ASM ????
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 04-02-2003, 04:28 AM
  2. << !! Posting Code? Read this First !! >>
    By kermi3 in forum C Programming
    Replies: 0
    Last Post: 10-03-2002, 03:04 PM
  3. << !! Posting Code? Read this First !! >>
    By biosx in forum C++ Programming
    Replies: 1
    Last Post: 03-20-2002, 12:51 PM
  4. Implementing "ls -al"
    By pdstatha in forum Linux Programming
    Replies: 11
    Last Post: 03-20-2002, 04:39 AM
  5. free() usage
    By pdstatha in forum C Programming
    Replies: 5
    Last Post: 03-13-2002, 09:28 AM