Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.2 9/18/84 SMI; site sun.uucp
Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!genrad!decvax!decwrl!sun!guy
From: guy@sun.uucp (Guy Harris)
Newsgroups: net.lang.c
Subject: Re: C programming hint
Message-ID: <2412@sun.uucp>
Date: Fri, 12-Jul-85 02:28:07 EDT
Article-I.D.: sun.2412
Posted: Fri Jul 12 02:28:07 1985
Date-Received: Sat, 13-Jul-85 12:15:10 EDT
References: <899@teddy.UUCP>
Organization: Sun Microsystems, Inc.
Lines: 17

> I found a way to initialize an array of characters without using a loop. ...
> 	strncpy(blanks + 1, blanks, SIZE - 1);	/* initialize entire array */

Ummm... there *is* a loop there; it just happens to be hidden in the
"strncpy" routine.  In some C libraries on some machines, this uses a faster
sequence to copy the data than the fastest C loop.  On other machines,
"strncpy" is just the obvious C loop (and you pay the overhead of a
subroutine call).  On other machines, "strncpy" might not work with
overlapped strings...

The System V C library has a routine called "memset" which can be used to
set a block of bytes to a specific value.  Modulo the subroutine call
overhead, this is probably the most efficent way of initializing the array
(the "strncpy" has to fetch byte N to move it to byte N+1; the "memset" can
keep that byte in a register).

	Guy Harris