www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/01/13/10:04:59

Date: Mon, 13 Jan 1997 16:25:25 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: Alaric Dailey <alaric AT oasis DOT novia DOT net>
cc: djgpp AT delorie DOT com
Subject: Re: catching a CTRL C / Just for Eli and DJ Delorie
In-Reply-To: <5bclkt$idc@nntp.novia.net>
Message-ID: <Pine.SUN.3.91.970113161505.10602E-100000@is>
MIME-Version: 1.0

On 13 Jan 1997, Alaric Dailey wrote:

> ctrlbrk.c:8: warning: passing arg2 of `signal; from incompatable pointer
> type
> 
> since it is only a warning when it finishes then runs as I expected it to,
> so now my questions change.  Although I am familiar with pointers, I am
> not great with them, so how do I fix the warning.

By looking in the docs and feeding `signal' with arguments it expects.  
`signal' needs a function which accepts an int and returns nothing, so 
you should make `terminate' to be like so:

void terminate (int signo)
{
        fprintf(stderr, "ending function called with signal %d!\n", signo);
        exit(0);
}

And also change `ctrlbrk' to be like so:

void ctrlbrk(void (*fptr)(int))
{
   signal(SIGINT,fptr);
}

> Second when you change
> the extention and compile it as c++ you get the errors that follows -
> 
> ctrlbrk.cc:5: `ftpr' was not declared in this scope

C++ requires that you put the declaration of fptr inside the parentheses; 
it doesn't allow K&R syntax.  So the above change in `ctrlbrk' should 
also solve your problems with C++ (although I didn't actually try this).

You should also get used to declaring your `main' "int main", but that's 
another story.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019