semantics of Memcpy macro in S.h

Douglas Bates (bates@stat.wisc.edu)
Fri, 23 Jan 1998 20:52:04 -0600 (CST)


I got caught on a subtle difference in the behaviour of the Memcpy
macro defined in the include file S.h and the memcpy system function
on some versions of Unix. This is a technical point and unless you
write C code for loading into S and you use this macro, you can safely
skip the rest of the message.

The Memcpy macro defined in S.h appears to call the memcpy system
function and one is tempted to think that it behaves in the same way.
In particular, memcpy returns a pointer to its "dest" argument so you
can use the result of the call to memcpy in a call to another
function. In some code for use with S I had written

return internal_loglik( dd, Memcpy( zxcopy2, zxcopy, zxdim ),
generate_DmHalf( dd, pars, pdC, Delta ),
setngs, DNULLP, DNULLP );

That works fine on any system when the memcpy function is defined. On
others where memcpy is not defined, in particular on Digital Unix,
memcpy is defined in S.h as a macro that generates the equivalent bcopy call
_except_ that bcopy doesn't return a pointer. The declarations are

void *memcpy(void *dest, const void *src, size_t n);

void bcopy (const void *src, void *dest, int n);

To get this to run on Digital Unix and perhaps other systems I needed
to replace that section with

Memcpy( zxcopy2, zxcopy, zxdim );
return internal_loglik( dd, zxcopy2,
generate_DmHalf( dd, pars, pdC, Delta ),
setngs, DNULLP, DNULLP );

-- 
Douglas Bates                            bates@stat.wisc.edu
Statistics Department                    608/262-2598
University of Wisconsin - Madison        http://www.stat.wisc.edu/~bates/