| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | using ctrlbrk() |
G'Day Paul,
-=> Quoting Paul Edwards to Frank Adam <=-
FA> puts("Quit ? (y/N)");
FA> if(getch() != 'y') return (1); /* nah */
FA> return (0); /* quit */
FA> }
PE> Well, you got me to look up my standard, but unless your section
PE> 7.7.1.1 is different from mine, the return value from your handler is
PE> irrelevant. Actually, not so much irrelevant as ILLEGAL.
From memory he was asking about ctrlbrk(), which is a borland function,
so i didn't bother looking in the standard at the time.
Ctrlbrk in TurboC is defined as void ctrlbrk(int *handler(void));
The online help goes s'thing like this..
If the handler function returns 0 the program is terminated, otherwise it
resumes execution.
I assume it is sort of a front end for signal().
PE> The signal handler is meant to be of return type "void".
I did look at ANSI, i presume you meant 4.7.1.1.
I'm back to my normal confused state now, the function definition does
indicate a void func..
void (*signal(int sig, void (*func)(int)))(int);
but later on it says..
executed. The function func may terminate by executing a return
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
statement or by calling the abort , exit , or longjmp function. If
^^^^^^^^^
func executes a return statement and the value of sig was SIGFPE or
any other implementation-defined value corresponding to a
computational exception, the behavior is undefined. Otherwise, the
program will resume execution at the point it was interrupted.
That sounds a bit contradictory, how can a void func(whatever) execute
a return statement ?
Just out of interest here is the TurboC example on signal()..
#pragma inline
#include
#include
void Catcher(int sig, int type, int *reglist)
{
printf("Caught it!\n");
*(reglist + 8) = 3; /* make return AX = 3 */
}
int main(void)
{
signal(SIGFPE, Catcher);
asm mov ax,07FFFH /* AX = 32767 */
asm inc ax /* cause overflow */
asm into /* activate handler */
/* The handler set AX to 3 on return. If that hadn't happened,
there would have been another exception when the next 'into'
was executed after the 'dec' instruction. */
asm dec ax /* no overflow now */
asm into /* doesn't activate */
return 0;
}
It didn't compile with 2 or 3 errors, neither could i work out where
this "reglist" is defined, yet the compiler didn't complain about it.
L8r Frank (fadam{at}ozemail.com.au).
___ Blue Wave/DOS v2.21
--- Gash
* Origin: The Software Parlour (3:635/544)SEEN-BY: 50/99 620/243 623/630 632/349 635/503 544 727 711/409 410 413 430 SEEN-BY: 711/808 809 932 934 712/515 713/888 714/906 800/1 @PATH: 635/544 50/99 711/808 934 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.