Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!rutgers!husc6!cmcl2!brl-adm!brl-smoke!gwyn From: gwyn@brl-smoke.UUCP Newsgroups: comp.lang.c Subject: Re: Copying a constant number of bytes Message-ID: <5976@brl-smoke.ARPA> Date: Sat, 13-Jun-87 22:36:46 EDT Article-I.D.: brl-smok.5976 Posted: Sat Jun 13 22:36:46 1987 Date-Received: Sun, 14-Jun-87 05:42:36 EDT References: <900@bloom-beacon.MIT.EDU> Reply-To: gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) Distribution: world Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 17 In article <900@bloom-beacon.MIT.EDU> newman@athena.mit.edu (Ron Newman) writes: >I want to copy a constant number of bytes NBYTES from address "a" >to address "b", where "a" and "b" are pointers of unspecified type. > bcopy ((char *)a, (char *)b, NBYTES); Always works (use memcpy rather than bcopy on ANSI-compatible systems). Does not necessarily involve a subroutine call (depends on implementation), and the calling overhead is not normally significant anyway. > struct nbytes {char s[NBYTES];}; > *(struct nbytes *)b = *(struct nbytes *)a; Not guaranteed to work. The reason for the existence of the str*() and mem*() routines in the first place is to provide implementation-independent access to implementation-specific "best" methods of doing these things. Use them.