Discuss Error disappears in debug mode in the C Programming forum on Dev Shed. Error disappears in debug mode C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
Posts: 13
Time spent in forums: 5 h 3 m 59 sec
Reputation Power: 0
Error disappears in debug mode
I have some evil error in my code, index out of bound probably. It overwrites some stuff in the programs code.
However in debug mode(im using NetBeans) it runs perfectly. Probably in debug mode it does some different memory allocation, I dont know.
Why is this? Whats the running/memory difference between normal run and debug mode?
Thanks a lot!
Posts: 3,835
Time spent in forums: 2 Months 3 Weeks 2 Days 16 h 3 m 48 sec
Reputation Power: 1774
> Why is this? Whats the running/memory difference between normal run and debug mode?
Consider something like this
char buff[10];
int i;
In debug mode, the compiler may allow more "dead space" at the end of the array to permit easier detection of buffer overruns. So it may allow 16 bytes for the array before storing the int.
In release mode, all it cares about is efficient allocation. In this case, the compiler would just round up to the next sizeof(int) boundary - say 12, and store the int.
Now, if in your code you have a buffer overrun up to say 14 chars, it will just fill the dead space in debug mode, and completely trash your int in release mode.
Netbeans seems to be just an IDE.
What is the operating system and compiler you're using?
Posts: 13
Time spent in forums: 5 h 3 m 59 sec
Reputation Power: 0
Quote:
Originally Posted by salem
> Why is this? Whats the running/memory difference between normal run and debug mode?
Consider something like this
char buff[10];
int i;
In debug mode, the compiler may allow more "dead space" at the end of the array to permit easier detection of buffer overruns. So it may allow 16 bytes for the array before storing the int.
In release mode, all it cares about is efficient allocation. In this case, the compiler would just round up to the next sizeof(int) boundary - say 12, and store the int.
Now, if in your code you have a buffer overrun up to say 14 chars, it will just fill the dead space in debug mode, and completely trash your int in release mode.
Netbeans seems to be just an IDE.
What is the operating system and compiler you're using?
Posts: 13
Time spent in forums: 5 h 3 m 59 sec
Reputation Power: 0
Sorry for the bump!
The problem is solved, maybe somebody will have the same thing once:
I forget to set a class member to null, so it was always the same crap in it from the previous function. The "error" disappeared in debug mode, and when I changed the prev function it made a slightly different error so I thought its the previous func
It was an evil error.