Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!sundc!sun!gorodish!guy From: guy%gorodish@Sun.COM (Guy Harris) Newsgroups: comp.lang.c Subject: Re: Type checking in conditional expressions Message-ID: <31175@sun.uucp> Date: Sun, 18-Oct-87 21:24:21 EDT Article-I.D.: sun.31175 Posted: Sun Oct 18 21:24:21 1987 Date-Received: Mon, 19-Oct-87 02:09:24 EDT References: <186@wright.EDU> Sender: news@sun.uucp Lines: 38 Keywords: HELP! > Here's what I'm doing. C compilers don't check the types > or number of parameters in function calls where the function is > external to the file being compiled. This has caused me lots of problems > since I'm forgetful and often goof up the actual parameter list for > my function calls. To provide this checking I created some macros of the > form... If you're working on a UNIX system, use "lint". If you're working on a non-UNIX system that has "lint" (I think there are, for example, "lint"s for the PC out there), use "lint". This does this sort of checking for you, *without* having to cook up that sort of macro or waste data space, etc. with dummy variables. It will also check for a lot of *other* problems, especially if you use the "-h" flag (or, in the case of later "lint"s, if you *don't* use the "-h" flag - the default for many of these useful tests was changed from "don't" to "do"). > After consulting K&R about the conditional operator, I tried > some simple test cases like > main() > { void function(); > void (*name)(); > name = function; > name = (0?name:function); > } > I figured if name and function were truly incompatible, the first > assignment should fail to compile, but it didn't. At the same time, > the compiler complained about the conditional expression in the last line. > > Could someone please explain to me what's going on here? Yes. What's happening here is that you're tickling a bug in the compiler. "name" and "function" are *not* incompatible; the compiler is just confused. This sounds like a PCC bug, which makes me suspect you're using UNIX, in which case you should use "lint" instead of that macro trick. (This bug is fixed in 4.3BSD.) Guy Harris {ihnp4, decvax, seismo, decwrl, ...}!sun!guytant,tant,tlif