[comp.lang.c] mixstrcpy

fmcwilli@oracle.oracle.com (Floyd McWilliams) (05/29/90)

In article <1990May28.190935.22913@druid.uucp> darcy@druid.UUCP
  (D'Arcy J.M. Cain) writes:

>#define mixstrcpy(d, s)  { int k = 0; do d[k] = s[k]; while (s[k++]);}

	This blows up if you try

	if (d && s)
           mixstrcpy(d,s);
        else ...

	(The semicolon after the mixstrcpy() invocation becomes a null
statement, and the "else" is left hanging.)

	Try wrapping the macro in do ... while(0), like this:

#define mixstrcpy(d,s) \
   do \
      { int k = 0; do d[k] = s[k]; while (s[k++]); } \
   while(0)

	Hope this helps(TM).
--
	Floyd McWilliams -- fmcwilli@oracle.com
	To be esteemed be useful.