lclint-interest message 191
From 100045.1545@compuserve.com Fri Feb 20 19:05:34 1998
Sender: 100045.1545@compuserve.com
Date: Fri, 20 Feb 1998 22:33:11 +0100 (CET)
From: Hermann Kleier <100045.1545@compuserve.com>
Reply-To: Hermann Kleier <100045.1545@compuserve.com>
To: lclint-discussions
Cc: Hermann Kleier
Subject: signal function interface
Mime-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII
I am confused by the function interface of `signal' and how LcLint handles
the confusion. LcLinting the two line file
> void signal (int, void (*) (int));
> #define SIG_ERR (void (*) (int)) -1
yields (standard mode):
> LCLint 2.3i --- 15 Sep 97
> Finished LCLint checking --- no code errors found
I tried to typedef the signal handler function and to use it:
> typedef void SignalHandlerT (int);
> void signal (int, SignalHandlerT *);
> #define SIG_ERR (SignalHandlerT *) -1
This time the output takes some more lines:
> LCLint 2.3i --- 15 Sep 97
>
> test.c:2,19: Parameter 2 of function signal has inconsistent type:
> declared SignalHandlerT *, specified [function (int)
> returns void] *
> Types are incompatible. (-type will suppress message)
> load file posixstrict.lcd: Specification: [function (int) returns
> void]
> *
> test.c: (in macro SIG_ERR)
> test.c:3,18: Constant SIG_ERR specified as [function (int) returns void]
> *, but defined as
> SignalHandlerT *: (SignalHandlerT *)-1
> A function, variable or constant is redefined with a different type.
> (-incondefs will suppress
> message)
> load file posixstrict.lcd: Specification of SIG_ERR
>
> Finished LCLint checking --- 2 code errors found
This is much stuff. Why that? Isn't the typedef-using file equivalent to
the 1st approach?
------------------------------------------------------
Another question:
LcLint declares `signal'
> void signal (int, void (*) (int));
to be a function taking a signal number and a pointer to a signal handler
and RETURNING NOTHING. What about checking the successfull installation
of signal handlers? ANSI C declares signal
> void (*signal (int sig, void (*func) (int)))(int);
to be a function taking a signal number and a pointer to a signal handler
and returning a pointer to a function taking an interger and returning
nothing (Plauger: P.J.: The Standard C Library. 1992, page 196). This can
be used to check the installation of a signal handler:
> old_handler = signal( sig, &new_handler );
The example is from Harbison, Steele: C, A Referenece Manual. 1991, page
356.
--------------------------------------------------------------
Any hints?
Hermann Kleier
David
Evans
University of Virginia, Computer Science
evans@cs.virginia.edu