 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Jack Crenshaw Guest
|
Posted: Mon Jan 12, 2004 4:25 pm Post subject: Help with asserts in console app |
|
|
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
|
Posted: Mon Jan 12, 2004 6:42 pm Post subject: Re: Help with asserts in console app |
|
|
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
|
Posted: Mon Jan 12, 2004 7:37 pm Post subject: Re: Help with asserts in console app |
|
|
| 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
|
Posted: Mon Jan 12, 2004 7:57 pm Post subject: Re: Help with asserts in console app |
|
|
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 |
|
 |
|
|
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
|
|