Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!rutgers!ames!ucbcad!ucbvax!sdcsvax!sdchem!tps From: tps@sdchem.UUCP Newsgroups: comp.lang.c Subject: Re: Incrementing of preprocessor symbols Message-ID: <679@sdchema.sdchem.UUCP> Date: Thu, 16-Apr-87 20:19:20 EST Article-I.D.: sdchema.679 Posted: Thu Apr 16 20:19:20 1987 Date-Received: Sat, 18-Apr-87 04:33:09 EST References: <3424@vrdxhq.UUCP> Sender: news@sdchem.UUCP Reply-To: tps@sdchemf.UUCP (Tom Stockfisch) Organization: UC San Diego Lines: 50 Keywords: C #define In article <3424@vrdxhq.UUCP> deller@vrdxhq.UUCP (Steven Deller) writes: >Help please. We have a program in which we would like to use something like: > > assert( ) ; > >and have it expand to > > if ( ! ) error_call( , __FILE__, __LINE__ ) ; > >Everything is quite easy to do with a #define, except the handling of . We >would like the to increment with each expansion encountered in the source, >i.e. with each "assert" in the text. The helps distinguish the different >assertions on VMS, where C does not expand __FILE__ and __LINE__... The only preprocessor variables are __FILE__ and __LINE__ -- you're out of luck. >We are not looking to use a pre-preprocessor that modifies the sources as they >are fed to the "cc" command (piping the source messes up __FILE__, and we can't >afford the extra time to make file copies);... Do what cpp does -- use the # line NNN FILENAME directive. No file copies are necessary, and __LINE__ and __FILE__ should be updated. >we are looking for a solution entirely within the C preprocessor. I agree this would be more desirable, even with the "#line" directive. >If as I am beginning to suspect, this is not possible with C, then >perhaps the C standards committee might take note. "__FILE__" and "__LINE__" are already in the standard, as well as "assert(x)". So you have to come up with another example to show the usefulness of yet another macro facility. -------- # define X 0 # define assert(x) if ( !x ) _assert( X #= X + 1, __LINE__, __FILE__ ); || Tom Stockfisch, UCSD Chemistry tps%chem@sdcsvax.ucsd.edu or sdcsvax!sdchem!tps