BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Help with asserts in console app

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (IDE)
View previous topic :: View next topic  
Author Message
Jack Crenshaw
Guest





PostPosted: Mon Jan 12, 2004 4:25 pm    Post subject: Help with asserts in console app Reply with quote




Does anyone have a suggestion for how to use asserts in a console app. Running inside the IDE, the window closes as soon as the assertion fails. Therefore I don't get to see which assertion failed. Microsoft puts up a separate dialog box showing the assertion.

Seems to me, one can't use asserts at all, the way things stand.

Jack
Back to top
Jack Crenshaw
Guest





PostPosted: Mon Jan 12, 2004 6:42 pm    Post subject: Re: Help with asserts in console app Reply with quote



Thanks, Bruce. I'll try it.

re the column: Stay tuned for results of this effort <grin>.

Jack

" Bruce Salzman" <bruce (AT) nospam (DOT) org> wrote:
Quote:
Does anyone have a suggestion for how to use asserts in a console app.
Running inside the IDE, the window closes as soon as the assertion fails.
Therefore I don't get to see which assertion failed. Microsoft puts up a
separate dialog box showing the assertion.

Seems to me, one can't use asserts at all, the way things stand.

Hi, Jack

You could try installing a signal "Catcher" routine to handle the abort
call in assert. See the following demo:

#include <assert.h
#include #include #include
#ifdef __cplusplus
typedef void (*fptr)(int);
#else
typedef void (*fptr)();

#endif

void Catcher(int *reglist)
{
signal(SIGABRT, (fptr)Catcher); // install signal handler
while (!kbhit()); // wait for key
}

int main(int argc, char* argv[])
{
signal(SIGABRT, (fptr)Catcher); /* cast Catcher to appropriate type */

assert(argc > 2);
printf("Hello, World!n");
return 0;
}

At least the window stays open until you hit a key...

Regards,
Bruce

PS. Looking forward your next Embedded Systems column!




Back to top
Bruce Salzman
Guest





PostPosted: Mon Jan 12, 2004 7:37 pm    Post subject: Re: Help with asserts in console app Reply with quote



Quote:
Does anyone have a suggestion for how to use asserts in a console app.
Running inside the IDE, the window closes as soon as the assertion fails.

Therefore I don't get to see which assertion failed. Microsoft puts up a
separate dialog box showing the assertion.
Quote:

Seems to me, one can't use asserts at all, the way things stand.

Hi, Jack

You could try installing a signal "Catcher" routine to handle the abort
call in assert. See the following demo:

#include <assert.h>
#include <signal.h>
#include <stdio>
#include <conio>

#ifdef __cplusplus
typedef void (*fptr)(int);
#else
typedef void (*fptr)();

#endif

void Catcher(int *reglist)
{
signal(SIGABRT, (fptr)Catcher); // install signal handler
while (!kbhit()); // wait for key
}

int main(int argc, char* argv[])
{
signal(SIGABRT, (fptr)Catcher); /* cast Catcher to appropriate type */

assert(argc > 2);
printf("Hello, World!n");
return 0;
}

At least the window stays open until you hit a key...

Regards,
Bruce

PS. Looking forward your next Embedded Systems column!



Back to top
Bruce Salzman
Guest





PostPosted: Mon Jan 12, 2004 7:57 pm    Post subject: Re: Help with asserts in console app Reply with quote

Oops!

void Catcher(int *reglist)
{
signal(SIGABRT, (fptr)Catcher); // install signal handler
while (!kbhit()); // wait for key
}

should be just

void Catcher(int *reglist)
{
while (!kbhit()); // wait for key
}


Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (IDE) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.