Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!rutgers!ames!ptsfa!ihnp4!cbosgd!wright!jholbach From: jholbach@wright.EDU (Jim Holbach) Newsgroups: comp.lang.c Subject: Type checking in conditional expressions Message-ID: <186@wright.EDU> Date: Sun, 18-Oct-87 00:59:37 EDT Article-I.D.: wright.186 Posted: Sun Oct 18 00:59:37 1987 Date-Received: Sun, 18-Oct-87 23:43:45 EDT Organization: Wright State University, Dayton OH, 45435 Lines: 54 Keywords: HELP! I have been using macros, dummy variables and the C conditional expression to provide some static type checking that C compilers don't provide. I have run into a snag that I couldn't explain or resolve after consulting K&R and was hoping that someone could help point me in the right direction. 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 #define PROCNAME(a,b) procname(0?dummy_a:(a),0?dummy_b:(b)) where procname is the function that I'm calling and dummy variables "dummy_a" and "dummy_b" of the correct types have been declared in the include file that contains the macro. Then when I call the function procname using PROCNAME(actual_a,actual_b) the compiler has to do type checking on the conditional expression (without incurring any run-time overhead). This isn't a perfect solution since if the compiler can bring the dummy variable and actual variable to a common type through "the usual arithmetic conversions", it doesn't complain (K&R 7.14). But at least it takes care of the grosser problems, like not using a pointer when one was expected, too many/too few arguments, etc. Unfortunately it's also complaining when (I think) it shouldn't. For example, I have a function which expects a function to be passed to it. So my dummy variable is declared as "void (*dummy_func)()". But when I invoke the macro using the name of the function as an argument, the compiler complains "operands of : have incompatible types". 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? Thanks. Jim Holbach ( jholbach@wright.edu ) Wright State University Dayton, Ohio