strncpy

Dr. T. Andrews tanner at ki4pv.UUCP
Thu Dec 28 00:42:45 AEST 1989


In <11527 at csli.Stanford.EDU>, From: poser at csli.Stanford.EDU (Bill Poser) writes...
) Only a genius like Dr. Tanner would think of not overflowing
) the buffer.
At the very least, we may assume that people at Stanford have not
considered allocating a buffer of sufficent size for their purposes.

) The "waste" of the terminating null is REQUIRED so long as one
) conforms to the usual, null-terminated representation of strings
) in C.
If one had strings which fit neatly into that mold, one would surely
use strcpy(), not strncpy().  Except, of course, at Stanford, where
strncpy() and on buffers of known size are an important subject of
research; we expect Mr. Poser's paper on the same shortly.

) All other representations of arbitrary length strings require
) similar overhead, e.g. a character count in the descriptor.
I beg to differ.  By defining storage fields of a certain size, and
using strncpy() to manipulate them, "strings" of that size may be
handled without character counts in the descriptors.

That a function strncpy() has been provided for such a cases is nice,
but simply a convenience.

That they don't teach people about character arrays of known size
at Stanford is purely a local teaching decision and therefore not
a suitable subject for outside debate.

Of course, it may not be all of Stanford.  It may just be that Mr.
Poser's brain is broken.
...!{bikini.cis.ufl.edu allegra attctc bpa uunet!cdin-1}!ki4pv!tanner



More information about the Comp.lang.c mailing list