On Sat, 2 May 1998, Chris Jacobson wrote:
> On 5/2/98 12:06 PM, George (greerga@CIRCLEMUD.ORG) stated:
>
> >Just to nitpick, that won't work unless you add {} to the if...else or
> >do{}while(0) to the macro.
>
> Is the `do' and `while(0)' parts really necessary?
>
> There are some sections of my code that I need to embed within a block,
> but aren't part of a control block... I simply use {...} without
> do/while(0)
> Neither of my compilers have complained (with full warnings on)...
If you are sure they will never be part of a control block, no. Otherwise,
what happens is that you want to put a ; after your macro call to make it
look like a normal C function, but with {} around it, putting a ;
afterwards will not work properly.
Try the following example, with and without do .. while(0) around it.
#include <stdio.h>
#define XYZZY { printf ("test.\n"); printf ("Test2\n"); }
int main()
{
if (1)
XYZZY;
else
printf ("Foo!\n");
return 0;
}
=============================================================================
Erwin Andreasen Herlev, Denmark <erwin@pip.dknet.dk> UNIX System Programmer
<URL:http://www.abandoned.org/drylock/> <*> (not speaking for) DDE
=============================================================================
+------------------------------------------------------------+
| Ensure that you have read the CircleMUD Mailing List FAQ: |
| http://democracy.queensu.ca/~fletcher/Circle/list-faq.html |
+------------------------------------------------------------+
This archive was generated by hypermail 2b30 : 12/15/00 PST