delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/12/21/20:36:51

From: shaka AT innotts DOT co DOT uk (Shaka Zulu)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: signal.h problem
Date: Tue, 22 Dec 1998 01:28:24 GMT
Message-ID: <36771eb1.136030246@news.innotts.co.uk>
References: <366ed03e DOT 127472077 AT news DOT innotts DOT co DOT uk> <366e3824 DOT 48335326 AT news DOT snafu DOT de>
X-Newsreader: Forte Agent 1.5/32.452
MIME-Version: 1.0
NNTP-Posting-Host: max-pool-p20.innotts.co.uk
Lines: 69
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

On Wed, 09 Dec 1998 11:16:47 GMT, horst DOT kraemer AT snafu DOT de (Horst
Kraemer) wrote:

>On Wed, 09 Dec 1998 02:36:35 GMT, shaka AT innotts DOT co DOT uk (Shaka Zulu)
>wrote:
>
>> Hi 
>> using djgcc 2.8.1, the following won't compile.
>> 
>> system(const char *command)
>> {
>> 	char buf[4];
>> 	extern sigint();
>> 
>> 	signal(SIGINT, SIG_IGN);
>> 	write(4, command, strlen(command)+1);
>> 	read(5, buf, 1);
>> 	signal(SIGINT, sigint);    \* error line *\
>> 	return(buf[0]<<8);
>> }
>> why does sigint produce the following error ?
>> 
>>     warning: passing arg 2 of `signal' from incompatible pointer type
>> 
>> my trusty c book state if a function address is used the specified
>> function is executed.
>
>The problem is that your declaration extern sigint(); declares 
>
>	int sigint();
>
>i.e. a function returning an int and taking an unspecified number of
>parameters, while the second parameter and the return value of
>signal() are declared in <signal.h> as
>
>"pointer to function returning nothing and taking an int parameter".
>
>With a typedef
>
>	typedef void (*pSighandler)(int);
>
>this prototype reads
>
>	pSighandler signal(int,pSighandler);
>
>Without typedef the prototype of 'signal' may look a little bit
>confusing
>
>	void (*signal(int,void (*)(int)))(int);
>
>Thus with the declaration
>
>	extern void sigint(int);
>
>you would declare a correct signal handler type required by the
>signal() prototype and your code should compile without warning.
>
>Regards
>Horst

tried it and it works ,
just need to see if it links 
once i,ve sorted the rest of the errors ,
by the way it isn't my code it's the 
Embeddable Common Lisp implementation.(ecl026.zip).
Thanx
Shaka


- Raw text -


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