Path: utzoo!mnetor!uunet!husc6!bloom-beacon!gatech!mcnc!decvax!ima!haddock!karl From: karl@haddock.ISC.COM (Karl Heuer) Newsgroups: comp.lang.c Subject: Re: While talking about useful additions, how about this one?? Message-ID: <2249@haddock.ISC.COM> Date: 13 Jan 88 23:20:24 GMT References: <253@vsi1.UUCP> Reply-To: karl@haddock.ima.isc.com (Karl Heuer) Organization: Interactive Systems, Boston Lines: 28 Summary: A simpler, yet more powerful, counterproposal In article <253@vsi1.UUCP> steve@vsi1.UUCP (Steve Maurer) writes: >While we are on the subject of useful additions to C, how about this >one: pre-compiler switching operators '??' and '::', which ask for >evaluation at compile time, instead of run time. The proposed syntax is bad: "??" conflicts with trigraph notation (if they're still in the standard), and "::" conflicts with C++ usage. >[If one attempts to define a macro POW(X,Y) as >Y == 0.5 ? sqrt(X) : Y == 0 ? 1 : Y == 1 ? X : Y == 2 ? X * X : pow(X,Y) >,] the resulting code is horrendous. If Y is a constant, any decent compiler will do the right thing. You don't need a new operator for that. If I understand your proposal, the only real enhancement is that "??" treats all non-constants as false. I counterpropose a builtin "isconstant()", which tests whether its argument is a compile-time constant. Thus, "isconstant(Y) && Y == 2 ? X * X : pow(X,Y)". This is a much smaller change than your proposal, and it's much easier to squeeze in a new unary operator than a new ternary. Karl W. Z. Heuer (ima!haddock!karl or karl@haddock.isc.com), The Walking Lint ________ Note 1: I intentionally removed the redundant parens to make it easier to concentrate on the issues at hand. Note 2: Although "pow" is used in the example, a macro can't solve the pow() problem. However, C++ overloading and inlining, combined with isconstant(), would do the trick.