Thread: Debug vs Release

  1. #1
    Registered User
    Join Date
    Jun 2006

    Debug vs Release

    I'm experiencing an odd issue with an application I have developed. It parses data from a file and later writes the required elements in a header for a different file. In Debug mode, it compiles perfectly but when I try to compile it in Release mode it writes the data incorrectly. Is there something different between the two that would alter such basic functionality?

    Here's an example of a proper vs. improper conversion.
    Note: Both outputs are all on one line but I didn't want to stretch the forum frame so I manually added the redundant breakline - also for clarity.

    Debug prints out the following (similar to what is read in from a separate file):
    11 "Input: WOW=True" CAS ADVISE\0
    12 "Input: Gear=True" CAS ADVISE\0
    13 "Input: Anti-Ice=True" EVENT MESSAGE\0
    14 "" IGNORE NONE\0
    Release is giving me:
    -591746099   \0
    1242140   \0
    2011353977   \0
    1815843632   \0

    The code writing this is an iteration through a type struct vector:
    unsigned char c = 0x0a;
    for (j=0; j<19; j++)
    	fprintf(out, "%d %s %s %s%c", Bits[j].Bit, 

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    The problem is almost certainly in the place where you're filling the fields, not where you're reading them.

    It seems as though it's not filling them at all. Does the call to the function that should be filling them perhaps look anything like this?
    assert(fillFields(...) != -1);
    I.e. is it within an assert or anything else that gets removed in release builds?
    All the buzzt!

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    Registered User
    Join Date
    Jun 2006
    I see what you're getting at, but the code is straight up as above. There is no call to a function and no assertions. The data is read in from a file to the global struct, then later writes the struct to another file as above. I looked through the code for a catch, but I can't find anything.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    > Is there something different between the two that would alter such basic functionality?
    If the code is bug-free, no.
    But what you may find is that memory is arranged differently between debug and release, so a buffer overrun in one may not actually cause any visible problem, but will cause the other to fail horribly.
    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.

  5. #5
    Registered User
    Join Date
    Jun 2006
    I scrutinized the code and found a foolish reference to an array location [-1] that was preventing the data-assignment code loop from running. Fixed it and things appear to be spot on regardless of Release or Debug build. Thanks for the help; I probably would have spent hours drilling myself before I'd realize that the assignment function wasn't executing properly. Even though now that I look at it, it was terribly obvious.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. debug release conf problem
    By fighter92 in forum Game Programming
    Replies: 6
    Last Post: 03-20-2009, 04:39 PM
  2. makefiles - debug & release?
    By cpjust in forum C Programming
    Replies: 6
    Last Post: 10-26-2007, 04:00 PM
  3. Results in Debug and Release mode are different
    By jaro in forum C Programming
    Replies: 11
    Last Post: 05-27-2006, 11:08 AM
  4. Release vs. Debug mode builds
    By earth_angel in forum C++ Programming
    Replies: 5
    Last Post: 11-10-2005, 04:41 PM
  5. debug to release modes
    By DavidP in forum Game Programming
    Replies: 5
    Last Post: 03-20-2003, 03:01 PM