Re: memcpy( dest, src, 0 )

From: Dan Pop (Dan.Pop_at_cern.ch)
Date: 07/01/04


Date: 1 Jul 2004 16:14:42 GMT

In <40E428E0.5020100@sun.com> Eric Sosman <Eric.Sosman@sun.com> writes:

>Peter Ammon wrote:
>> Eric Sosman wrote:
>>
>>> Spacen Jasset wrote:
>>>
>>>> given:
>>>>
>>>> memcpy( dest, src, 0 )
>>>>
>>>> What happens when the size paramater of memcpy is 0? Do the src and dest
>>>> have to be valid? It doesn't say anything about this in the standard
>>>> as far
>>>> as I can tell. So presumably they do have to be valid even when the
>>>> size is
>>>> 0.
>>>
>>> They must be valid. See section 7.1.4, paragraph 1. The
>>> general contract is that all arguments to library functions
>>> must be "real" unless the function's description explicitly
>>> permits "strange" arguments.
>>
>> Are there any examples of the latter?
>
> Others have pointed out some functions that accept NULL
>arguments. Here's a possibly odder example:
>
> char notstring[13] = "Hello, world!"; // no trailing zero
> printf ("%.6s strange new world!\n", notstring);
>
>The "%s" specifier usually takes an argument that points to
>the start of a zero-terminated C string, but when a precision
>is specified the argument need only point to the start of an
>array of `char', not necessarily zero-terminated.

I must be missing something. What is the chapter and verse from which
your example is an exception?!? What makes your example strange in any
way?

     s If no l length modifier is present, the argument shall
              be a pointer to the initial element of an array of
              character type.

Dan

-- 
Dan Pop
DESY Zeuthen, RZ group
Email: Dan.Pop@ifh.de


Relevant Pages

  • Re: which is the better path
    ... >The conversion rule only applies if the expression is not the operand of ... An exception that is not *explicitly* mentioned in a reply, ... Dan Pop ...
    (comp.lang.c)
  • Re: addresses and integers
    ... The standard says that it's valid (with one exception) and that the ... where the pointer value is not the same as the address pointed ... meaning. ... Dan Pop ...
    (comp.lang.c)
  • Re: where wrong?how to correct?and why? thank you
    ... Congratulations! ... With the exception of the braces, ... Dan Pop ...
    (comp.lang.c)