Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!caip!think!nike!ll-xn!cullvax!drw From: drw@cullvax.UUCP (Dale Worley) Newsgroups: net.lang.c Subject: Disappearing function call Message-ID: <357@cullvax.UUCP> Date: Wed, 1-Oct-86 16:16:01 EDT Article-I.D.: cullvax.357 Posted: Wed Oct 1 16:16:01 1986 Date-Received: Fri, 3-Oct-86 10:32:28 EDT Organization: Cullinet Software, Inc., Westwood, MA Lines: 53 What I want to do is to write a function call of a variable number of arguments: debug(x, y, z, ...) that will generate no code when the symbol DEBUG is not defined, but generate a call of some function (say, debug_()) when it is. If debug() always had the same number of arguments, we could use #ifdef DEBUG #define debug(x, y, z) debug_(x, y, z) #else #define debug(x, y, z) /* null */ but macros aren't allowed to have a variable number of arguments. The best solutions I've heard so far are: 1) We write debug(x Z y Z z) using "Z" instead of ",". Using the definitions #ifdef DEBUG #define debug(x) debug_(x) #define Z , #else #define debug(x) /* null */ #endif works, since the "Z"s are turned into "," after the call of debug() is expanded. This is ugly because you have to write "Z" instead of ",". 2) We write debug(x, y, z)) Using the definitions #ifdef DEBUG #define debug (debug_ #else #define debug debug1( #define debug1(x) /* null */ This works when DEBUG is off by replacing the call to debug() to a call to debug1() with one argument, which is then ignored. This ugly because of the mismatched parentheses. Is there a good way to do this? Dale