[net.lang.c] What should be added to C, call

aglew@ccvaxa.UUCP (05/30/86)

>>>> o The ability to define multi-line pre-processor macros, using #begdef and
>>>> #enddef statements.  #if and other conditionals in the body of the
>>>> definition would be evaluated when the macro was not interpreted, not when
>>>> it is encountered.
>>>
>>>Why would you want to use it?
>>
>>When your macro won't fit on a line, and/or you want to use #if's etc
>>as part of the macro, obviously. 
>
>If your macro won't fit on a line, you can already handle this problem by
>finishing off each line except the last with a backslash.
>The other addition would be a win, though.

Sorry, backslashes don't help macros that I want to have conditional
sections of code in. Eg. I can't do

#define debugf(parmlist) \
#ifdef DEBUG \
	printf parmlist \
#else \
	/* nothing */ \
#endif

I have to embed the #define within the #if instead.

NB. I can't even do this if I finish each line by \\\, unfortunately.

However, if you're going to have a multiline macro sequence, it would
be nice to have some way of distinguishing conditionals that I want
evaluated when the macro is recognized from conditionals that I
want evaluated at macro use time. All of these problems have been solved 
a hundred times in various macro languages - the solutions are all
#######iffy.

Andy "Krazy" Glew. Gould CSD-Urbana.    USEnet:  ihnp4!uiucdcs!ccvaxa!aglew
1101 E. University, Urbana, IL 61801    ARPAnet: aglew@gswd-vms

david@sun.uucp (David DiGiacomo) (06/04/86)

In article <2600062@ccvaxa> aglew@ccvaxa.UUCP (Andy "Krazy" Glew) writes:
>Sorry, backslashes don't help macros that I want to have conditional
>sections of code in. Eg. I can't do
>
>#define debugf(parmlist) \
>#ifdef DEBUG \
>	printf parmlist \
>#else \
>	/* nothing */ \
>#endif

There is a simple way to do this if you are willing to define one extra
macro for each condition you want to test within a macro definition.

#define	IFTRUE(a,b) a
#define	IFFALSE(a,b) b

#ifdef DEBUG
#define	IFDEBUG	IFTRUE
#else
#define	IFDEBUG	IFFALSE
#endif

#define	debugf(parmlist) IFDEBUG(printf parmlist, )

aglew@ccvaxa.UUCP (06/18/86)

... > Multiple way ifs and cases:

I prefer a syntax something like this:

	IF x < y THEN ....
	:: x = y THEN ....
	:: x > y THEN ....
	ENDIF

where :: means "evaluate alternative concurrently", and is distinct from
"else" in that it applies no sequentialization of the tests.

For people into theory, this is really just a guarded statement `a la
Dijkstra.

And, no, I do not propose to put this into C.

Andy "Krazy" Glew. Gould CSD-Urbana.    USEnet:  ihnp4!uiucdcs!ccvaxa!aglew
1101 E. University, Urbana, IL 61801    ARPAnet: aglew@gswd-vms