Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.2 9/18/84; site calgary.UUCP
Path: utzoo!watmath!clyde!burl!ulysses!mhuxr!ihnp4!alberta!calgary!radford
From: radford@calgary.UUCP (Radford Neal)
Newsgroups: net.lang.c
Subject: Re: context-independent macros
Message-ID: <949@calgary.UUCP>
Date: Mon, 4-Feb-85 19:03:05 EST
Article-I.D.: calgary.949
Posted: Mon Feb  4 19:03:05 1985
Date-Received: Sun, 10-Feb-85 03:07:56 EST
References: <1885@wateng.UUCP> <1089@hcrvx1.UUCP> <33@daisy.UUCP> <1097@hcrvx1.UUCP> <695@ucbtopaz.CC.Berkeley.ARPA>
Organization: University of Calgary, Calgary, Alberta
Lines: 41

> Instead of:
> 	# define macro(args)\
> 		if (1) {\
> 			/* macro body */\
> 		}\
> 		else
> 
> How about:
> 	#define	macro(args)\
> 		(Statement1 ,\
> 		Statement2 ,\
> 		...
> 		Statement3)
> 
> This should work correctly...

It doesn't work correctly. The statements might not be expressions (e.g. they
could be loops).

I posted a flame months ago on the deficiencies of the preprocessor. I
advocated an "inline" attribute for procedures to allow one to avoid its use.
It is quite impossible to write a macro to duplicate the following (for 
example):

   int f(a)
     char *a;
   { int c;
     c = 0;
     while (*a) { putchar(*a); c += 1; a += 1; }
     return c;
   }

The example above, however, can be done repressing only moderate amounts of
disgust via:

   #define macro(args) do { statement1; statement2; ... ; } while (0)

Note no semicolon at the end.

     Radford Neal
     The University of Calgary