mixstrcpy() macro (was Re: Using small memory model...)
Floyd McWilliams
fmcwilli at oracle.oracle.com
Wed May 30 02:48:24 AEST 1990
In article <1990May28.190935.22913 at druid.uucp> darcy at 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 at oracle.com
To be esteemed be useful.
More information about the Comp.lang.c
mailing list