Debug vs Release

This is a discussion on Debug vs Release within the Windows Programming forums, part of the Platform Specific Boards category; I'm experiencing an odd issue with an application I have developed. It parses data from a file and later writes ...

  1. #1
    tao
    tao is offline
    Registered User
    Join Date
    Jun 2006
    Posts
    26

    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):
    Code:
    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:
    Code:
    -591746099   \0
    1242140   \0
    2011353977   \0
    1815843632   \0

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

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    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?
    Code:
    assert(fillFields(...) != -1);
    I.e. is it within an assert or anything else that gets removed in release builds?
    All the buzzt!
    CornedBee

    "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
    tao
    tao is offline
    Registered User
    Join Date
    Jun 2006
    Posts
    26
    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,548
    > 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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    tao
    tao is offline
    Registered User
    Join Date
    Jun 2006
    Posts
    26
    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, 03:41 PM
  5. debug to release modes
    By DavidP in forum Game Programming
    Replies: 5
    Last Post: 03-20-2003, 02:01 PM

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