|
From: jo m. <non...@ho...> - 2003-10-10 10:04:13
|
I don't know what you mean by "compiling in debug mode", but if you want the
"assertions" not to be compiled I think you should
#define NDEBUG
either in the source code or trough the command line.
I hope it helps.
>From: Wobien <wo...@pl...>
>Reply-To: Wobien <wo...@pl...>
>To: dev-cpp-users-list <dev...@li...>
>Subject: [Dev-C++] using assert
>Date: Thu, 09 Oct 2003 16:27:45 +0200
>
>Using assert is supposed to be a big help in finding bugs in your program.
>
>#include <cassert>
>assert(a<b);
>
>should stop your program if a>=b and print the file and line number of the
>assert statement that failed, if and only if you run in debug mode. If you
>are not in debug mode, the assert statements should not be compiled.
>
>Now I have 2 problems:
>
>1: my program stops if the assert fails, even if I did not compile in the
>debug mode.
>
>2: when the program stops it does not wait and stop to give me the
>opportunity to read the message about the file and line number. The system
>("PAUSE"); statement at the end of the main procedure does not help here,
>because the program never gets there.
>
>A simple test "program" to try this is:
>
>#include <stdlib.h>
>#include <cassert>
>int main()
>{
> int a=5;
> int b=1;
> assert(a<b);
> system ("PAUSE");
> return 0;
>}
>
_________________________________________________________________
Help STOP SPAM with the new MSN 8 and get 2 months FREE*
http://join.msn.com/?page=features/junkmail
|
|
From: Damien A <g_...@ho...> - 2003-10-10 10:08:12
|
<html><div style='background-color:'><DIV>
<P><BR><BR></P>
<DIV></DIV>
<P><BR><BR></P></DIV>
<DIV></DIV>
<DIV></DIV><?xml:namespace prefix = mailto /><mailto:dev...@li...?subject=help><mailto:dev...@li...><mailto:dev...@li...?subject=subscribe><mailto:dev...@li...?subject=unsubscribe>
<DIV></DIV>
<DIV></DIV>
<DIV></DIV>
<DIV></DIV>
<DIV></DIV>
<DIV></DIV>1)After checking the assert.h header file included in cygwin, I saw this
<DIV></DIV>
<P>/*<BR> assert.h<BR>*/</P>
<DIV></DIV>
<P>#ifdef __cplusplus<BR>extern "C" {<BR>#endif</P>
<DIV></DIV>
<P>#include "_ansi.h"</P>
<DIV></DIV>
<P>#undef assert</P>
<DIV></DIV>
<P>#ifdef NDEBUG /* required by ANSI standard */<BR>#define assert(p) ((void)0)<BR>#else</P>
<DIV></DIV>
<P>So you see why it still compiled even without being in debug mode. You are required to define NDEBUG.</P>
<DIV></DIV>
<DIV></DIV>
<DIV></DIV>
<DIV></DIV>2) Different compilers handle assert differently, but in this case, the message is sent to the console window, so I suggest running the program from the console and see the result. If you have VC++6, try this program.
<DIV></DIV>
<P>#define WIN32_LEAN_AND_MEAN<BR>#include <windows.h><BR>#include <stdlib.h><BR>#include <cassert><BR>int __stdcall WinMain(HINSTANCE,HINSTANCE,LPSTR,int)<BR>{<BR> int a=5;<BR> int b=1;<BR> assert(a<b);<BR> system ("PAUSE");<BR> return 0;<BR>}</P>
<DIV></DIV>
<DIV></DIV>
<DIV></DIV>
<DIV></DIV>
<DIV></DIV>
<DIV></DIV>
<DIV></DIV>
<DIV></DIV>
<DIV></DIV>
<DIV></DIV>
<P>It'll give you the message box you so desire :)</P>
<P>------------------------------------------------------- </P>
<DIV></DIV>
<DIV></DIV>This SF.net email is sponsored by: SF.net Giveback Program.
<DIV></DIV>
<DIV></DIV>SourceForge.net hosts over 70,000 Open Source Projects.
<DIV></DIV>
<DIV></DIV>See the people who have HELPED US provide better services:
<DIV></DIV>
<DIV></DIV>Click here: http://sourceforge.net/supporters.php
<DIV></DIV>
<DIV></DIV>_______________________________________________
<DIV></DIV>
<DIV></DIV>Dev-cpp-users mailing list
<DIV></DIV>
<DIV></DIV>Dev...@li...
<DIV></DIV>
<DIV></DIV>TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
<DIV></DIV>
<DIV></DIV>https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
<DIV></DIV>
<DIV></DIV></mailto:dev...@li...?subject=unsubscribe></mailto:dev...@li...?subject=subscribe></mailto:dev...@li...></mailto:dev...@li...?subject=help></div><br clear=all><hr>Help STOP SPAM with <a href="http://g.msn.com/8HMBEN/2731??PS=">the new MSN 8 </a> and get 2 months FREE*</html>
|
|
From: Wobien <wo...@pl...> - 2003-10-10 21:14:15
|
Thanks Daniel and others for your suggestions.
The #define NDEBUG suggested by jo mateix works fine to prevent the
assertions to compile.
I already tried to run my program from the DOS prompt, but I did it by
closing Windows and start computer in DOS mode. When I do that I get "This
program cannot be run in the DOS mode".
When I do it the way Daniel suggests it works fine, and I can read the
message.
Wobien
----- Original Message -----
From: "Daniel Glenfield" <sp...@ho...>
To: <wo...@pl...>
Sent: Friday, October 10, 2003 11:54 AM
Subject: Re: [Dev-C++] using assert
> Try something like
>
> #if DEBUG
> assert(a<b);
> #endif
>
> and see if that does anything when compiling in Release mode.
>
> As for the irritating closing of the console window you'll need to run the
> program from a dos prompt.
>
> So do Start -> Accessories -> Command Prompt (it all depends on what OS
you
> have - in ME it is in Start itself).
> Type
> cd C:\Dev-CPP\MyTest\ <--- this is where the exe is
>
> then type
> MyTestProgram.exe
>
> That should work.
>
> Daniel
>
>
> >From: Wobien <wo...@pl...>
> >Reply-To: Wobien <wo...@pl...>
> >To: dev-cpp-users-list <dev...@li...>
> >Subject: [Dev-C++] using assert
> >Date: Thu, 09 Oct 2003 16:27:45 +0200
> >
> >Using assert is supposed to be a big help in finding bugs in your
program.
> >
> >#include <cassert>
> >assert(a<b);
> >
> >should stop your program if a>=b and print the file and line number of
the
> >assert statement that failed, if and only if you run in debug mode. If
you
> >are not in debug mode, the assert statements should not be compiled.
> >
> >Now I have 2 problems:
> >
> >1: my program stops if the assert fails, even if I did not compile in the
> >debug mode.
> >
> >2: when the program stops it does not wait and stop to give me the
> >opportunity to read the message about the file and line number. The
system
> >("PAUSE"); statement at the end of the main procedure does not help here,
> >because the program never gets there.
> >
> >A simple test "program" to try this is:
> >
> >#include <stdlib.h>
> >#include <cassert>
> >int main()
> >{
> > int a=5;
> > int b=1;
> > assert(a<b);
> > system ("PAUSE");
> > return 0;
> >}
> >
> >
> >
> >-------------------------------------------------------
> >This SF.net email is sponsored by: SF.net Giveback Program.
> >SourceForge.net hosts over 70,000 Open Source Projects.
> >See the people who have HELPED US provide better services:
> >Click here: http://sourceforge.net/supporters.php
> >_______________________________________________
> >Dev-cpp-users mailing list
> >Dev...@li...
> >TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> >https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
> _________________________________________________________________
> Stay in touch with absent friends - get MSN Messenger
> http://www.msn.co.uk/messenger
>
|
|
From: Mark L. <mli...@ip...> - 2003-10-11 05:23:34
|
On Thu, 09 Oct 2003 16:27:45 +0200 Wobien <wo...@pl...> wrote:
W> Using assert is supposed to be a big help in finding bugs in your program.
W>
W> #include <cassert>
W> assert(a<b);
W>
W> should stop your program if a>=b and print the file and line number of the
W> assert statement that failed, if and only if you run in debug mode. If you
W> are not in debug mode, the assert statements should not be compiled.
W>
W> Now I have 2 problems:
W>
W> 1: my program stops if the assert fails, even if I did not compile in the
W> debug mode.
Wrap it in some compile time checked #defines.
W> 2: when the program stops it does not wait and stop to give me the
W> opportunity to read the message about the file and line number. The system
W> ("PAUSE"); statement at the end of the main procedure does not help here,
W> because the program never gets there.
W>
W> A simple test "program" to try this is:
W>
W> #include <stdlib.h>
W> #include <cassert>
W> int main()
W> {
W> int a=5;
W> int b=1;
W> assert(a<b);
W> system ("PAUSE");
W> return 0;
W> }
Would you accept "start using wxWindows then you can have more intelligent
assert processing / logging" as an answer? ;-) Thereagain, you are using C and
not C++ so that may not be such a good answer anyway.
MarkL
|