Debug Build works Release build doesn't? 
Author Message
 Debug Build works Release build doesn't?

What could cause a program that compiles with no errors in release or debug
builds.  When I run the program in debug it works fine, but when I run the
same code in Release build the portion of my code that checks to see if the
user entered a valid integer fails, and will not recognize and int that I
enter.

Does anyone have any ideas?  I am using the two function below to check for
int.

Thanks
Tom

int getInt()
{
 // Local data ...
 String inString;            // the input String from the user
    int    finalValue;          // the value that gets returned
 bool   good = false;        // remains false until a valid
                             // string has been entered

 // Logic ...
 // Keep on getting Strings from user until the
 // user enters a valid String
 cin >> inString;
 getRidOfTrailingBlanks(inString);
 while (good == false)
 {
  // Check to see if syntax is good
  if (!isGoodInt(inString))
  {
     cout << "The value you entered is not a legal int value. " << endl;
     cout << "Please try again: ";
     cin  >> inString;
     getRidOfTrailingBlanks(inString);
     continue;      // try loop again
  }

  // Good syntax, but it may be out of range
  if (!withinIntRange(inString, finalValue))
  {
   cout << "The value you entered is too large or too small. " << endl;
   cout << "Please try again: ";
   cin  >> inString;
   getRidOfTrailingBlanks(inString);
   continue;     // try loop again
  }

  // Good syntax and good range; terminate loop
  // finalValue is the value we want
  good = true;
 } // while

 // inString is valid and finalValue is the value we want
 return finalValue;

Quote:
}  // end getInt

bool isGoodInt(const String& aString)
{
 // Local data ...
    int index;         // index into string

 // Logic ...
 // Skip over leading blanks until a sign or
 // a digit is encountered.  If the first non-blank
 // is not a sign or a digit, then return false
 index = 0;
 while (aString[index] == BLANK)
 {
  index++;
 }

 // We are looking at a non-blank character.   If it
 // is neither a sign nor a digit, return false
 if (!isSign(aString[index]) && !isdigit(aString[index]))
 {
  return false;
 }

 // If we are looking at a sign, the next character
 // must be a digit.
 if (isSign(aString[index]))
 {
  if (!isdigit(aString[index + 1]))
  {
   // illegal string
   return false;
  }
 }

 // aString[index] is a sign or a digit.  If it is a sign,
 // the next character is a digit.  From this point
 // on, until we reach the string terminator, all of the
 // chars must be digits.
 index++;
 while (aString[index] != TERMINATOR)
 {
  if (!isdigit(aString[index]))
  {
   return false;
  }
  index++;
 }

 // This is a legal int string
 return true;

Quote:
}  // end isGoodInt



Wed, 14 Aug 2002 03:00:00 GMT  
 Debug Build works Release build doesn't?
I can't see anything obvious in your code.

One known culpritt is the use of ASSERT() containing production code e.g.

ASSERT(do something important);

The code 'do something important' will be ommited from the release build.

Another culpritt is a bug in the optimizer, but this is pretty rare. You can
test this theory by turning off the optimizer in the relase build using the
project settings.

However just because turning off the optimizer fixes the problem you can not
be 100% sure the optimizer is the cause of the problem, it may just be
because the unoptimized code is moved things around in memory.

Look for uninitialized variables etc.

Good luck.

Joel


Quote:
> What could cause a program that compiles with no errors in release or
debug
> builds.  When I run the program in debug it works fine, but when I run the
> same code in Release build the portion of my code that checks to see if
the
> user entered a valid integer fails, and will not recognize and int that I
> enter.

> Does anyone have any ideas?  I am using the two function below to check
for
> int.

> Thanks
> Tom

> int getInt()
> {
>  // Local data ...
>  String inString;            // the input String from the user
>     int    finalValue;          // the value that gets returned
>  bool   good = false;        // remains false until a valid
>                              // string has been entered

>  // Logic ...
>  // Keep on getting Strings from user until the
>  // user enters a valid String
>  cin >> inString;
>  getRidOfTrailingBlanks(inString);
>  while (good == false)
>  {
>   // Check to see if syntax is good
>   if (!isGoodInt(inString))
>   {
>      cout << "The value you entered is not a legal int value. " << endl;
>      cout << "Please try again: ";
>      cin  >> inString;
>      getRidOfTrailingBlanks(inString);
>      continue;      // try loop again
>   }

>   // Good syntax, but it may be out of range
>   if (!withinIntRange(inString, finalValue))
>   {
>    cout << "The value you entered is too large or too small. " << endl;
>    cout << "Please try again: ";
>    cin  >> inString;
>    getRidOfTrailingBlanks(inString);
>    continue;     // try loop again
>   }

>   // Good syntax and good range; terminate loop
>   // finalValue is the value we want
>   good = true;
>  } // while

>  // inString is valid and finalValue is the value we want
>  return finalValue;
> }  // end getInt

> bool isGoodInt(const String& aString)
> {
>  // Local data ...
>     int index;         // index into string

>  // Logic ...
>  // Skip over leading blanks until a sign or
>  // a digit is encountered.  If the first non-blank
>  // is not a sign or a digit, then return false
>  index = 0;
>  while (aString[index] == BLANK)
>  {
>   index++;
>  }

>  // We are looking at a non-blank character.   If it
>  // is neither a sign nor a digit, return false
>  if (!isSign(aString[index]) && !isdigit(aString[index]))
>  {
>   return false;
>  }

>  // If we are looking at a sign, the next character
>  // must be a digit.
>  if (isSign(aString[index]))
>  {
>   if (!isdigit(aString[index + 1]))
>   {
>    // illegal string
>    return false;
>   }
>  }

>  // aString[index] is a sign or a digit.  If it is a sign,
>  // the next character is a digit.  From this point
>  // on, until we reach the string terminator, all of the
>  // chars must be digits.
>  index++;
>  while (aString[index] != TERMINATOR)
>  {
>   if (!isdigit(aString[index]))
>   {
>    return false;
>   }
>   index++;
>  }

>  // This is a legal int string
>  return true;
> }  // end isGoodInt



Wed, 14 Aug 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Debug build works correctly but release build doesnt (sometimes)

2. Debug build works, release build crashes!

3. VC6 Debug Build Works Fine - but Release Build Gives Error

4. Q: Dialog Tooltips work in DEBUG build but not under RELEASE Build

5. Debug build works correctly but release build doesnt (sometimes)

6. CDatabase doesn't seem to be working in Release builds

7. CMenu::CheckMenuItem doesn't work in release build

8. Strange problem: release build crashes, debug doesn't

9. CImageList doesn't work in release builds???

10. NMAKE doesn't work for debug build

11. Debug build breaks, Release build ok

12. Debug Build vs. Release Build

 

 
Powered by phpBB® Forum Software