Interpretation question: Pointers to explicitly zero-length strings

Jerry Leichter leichter at CS.YALE.EDU
Sat Jul 8 05:04:53 AEST 1989


A number of the ANSI C library functions accept a string argument, together
with a maximum length.  Obvious examples include strncpy and printf (%s can
accept a maximum length).  If the maximum length given is zero, must the
pointer passed be valid?  In particular, may it be 0, as in:

	strncpy(s,NULL,0);

This may sound like a silly question if you look only at an isolated example
with constants in it, but it arises naturally when dealing with strings
represented using a (length,pointer) structure.  When the length is 0, it
makes little difference where the pointer points, but it is often simplest -
in initialization, for example - to let it just be 0.

							-- Jerry



More information about the Comp.std.c mailing list