Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!hao!ames!oliveb!sun!gorodish!guy From: guy%gorodish@Sun.COM (Guy Harris) Newsgroups: comp.lang.c Subject: Re: Talking of void ... Message-ID: <32081@sun.uucp> Date: Tue, 27-Oct-87 13:22:20 EST Article-I.D.: sun.32081 Posted: Tue Oct 27 13:22:20 1987 Date-Received: Fri, 30-Oct-87 03:28:46 EST References: <1400@mhres.mh.nl> <31905@sun.uucp> <1407@mhres.mh.nl> Sender: news@sun.uucp Lines: 36 Keywords: return void cast > There are two reasons to return a value: one to keep lint from > complaining, and the other reason is a matter of programming principles. If > a function is typed, I always use an explicit return value. Which is precisely why "void ()" is the correct type for a signal handler function, since the value it returns isn't used.... The only reason why it was "int ()" is that "void" didn't exist as a C data type when the C-language version of the UNIX signal mechanism first appeared. As such, "int ()" had to serve a dual purpose; it was used both for functions returning "int" and for functions returning nothing. (This unfortunately meant that the C compiler could not complain about functions declared (explicitly or implicitly) as "int" that didn't return values.) Signal handlers *really* aren't "int ()"; their data type can be best described as "poor man's 'void ()'". Now that "void" is supported in most C implementations, the data type has been changed to "void ()". Given that, and given the problems you have with moving signal handlers that really return a value to modern systems with the proper type for signal handlers, it would be better *not* to consider signal handlers really to be "int ()", treat them as "void ()" (just not declaring them as such on older systems), and don't have them return a value. As for "lint", well, for the same reason the C compiler doesn't complain about "int ()" functions that don't return values, "lint" doesn't complain about them either. It only complains if a function returns a value sometimes but not other times, or if a function returns no value but somebody uses the non-existent value (another good reason for using "void" - the *compiler* can reject code that attempts to use the non-existent "value" of a "void ()" function). (The C++ compiler (the 1.1 version, anyway) *will* give a warning if you have a function declared as "int" that doesn't return a value.) Guy Harris {ihnp4, decvax, seismo, decwrl, ...}!sun!guy guy@sun.com