TIP: Click on subject to list as thread! ANSI
echo: os2prog
to: Donald Heering
from: Eric Weigel
date: 1995-05-03 01:23:00
subject: BCOS/2 1.0 signal() func

DH>Hello Mario,

DH># Sun 23 Apr 1995 05:49, you wrote to Donald Heering:

DH> DH> I constantly get something like "parameter mismatch in
DH> DH> __func" when trying to install a control-C handler.

DH> MS> I have installed a ctrl-c header some time ago. but can;t
DH> MS> find the code at the moment.

DH>Ah, if you find it, could you please send me a sample by netmail?

DH> MS> as i remember, you have to look carfully into signal.h to check
DH> MS> the type of the function.

DH>I did. The strange thing is, it works with the BC compiler.
DH>And according to the BCOS/2 manuals, the same code should
DH>work with BCOS/2.

DH> MS> here is the 2nd parameter (from bcos2.h)

DH> MS>     void (__cdecl * __func)(int)

DH>I've declared and defined it as follows:

DH>void cbrk_handler(void);

DH>void cbrk_handler(void)
DH>{
DH>    char c;
DH>    int  x, y;

DH>    signal(SIGINT, SIG_IGN);

DH>    /* Actual handler deleted */

DH>    signal(SIGINT, cbrk_handler);
DH>}

DH>Yet, I get an compiler error on:

DH>signal(SIGINT, cbrk_handler);


And so you should.  The default function calling convention in BC for
DOS was "cdecl".  BC OS/2 has a default of "stdcall,"
which is supposed
to be better.  The signal handler must be "cdecl."  Declare and define
as follows:

 void cdecl cbrk_handler(int sig);        //declare the handler

 void cdecl cbrk_handler(int sig)         //define the handler
 {
    char c;
    int  x, y;

    signal(SIGINT, SIG_IGN);

    /* Actual handler deleted */

    signal(SIGINT, cbrk_handler);
 }

Notice that the compiler will issue a warning for an unused paramter
"sig."  Notice also that the variable sig wil be equal to SIGINT if that
is the cause of the signal.  You will also want to install a handler for
SIGBREAK, to use the same handler change the code to:

 void cdecl cbrk_handler(int sig)         //define the handler
 {
    char c;
    int  x, y;

    signal(sig, SIG_IGN);                 //changed here

    /* Actual handler deleted */

    signal(sig, cbrk_handler);            //and here
 }

This will also eliminate the warning message.

___
 X SLMR 2.1a X 

--- Maximus/2 2.02
* Origin: Bob's Bored/2 (1:244/440)
SEEN-BY: 105/42 620/243 711/401 409 410 413 430 807 808 809 934 955 712/407
SEEN-BY: 712/515 628 704 713/888 800/1 7877/2809
@PATH: 244/400 250/702 3615/50 396/1 270/101 105/103 42 712/515 711/808 809
@PATH: 711/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™.