Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #21941

Re: copy size

From Keith Thompson <kst-u@mib.org>
Newsgroups comp.lang.c
Subject Re: copy size
Date 2012-06-07 22:40 -0700
Organization None to speak of
Message-ID <lnehpqcqe3.fsf@nuthaus.mib.org> (permalink)
References <03c3ed4d-f3ce-437b-9476-1c512c7772de@o3g2000pby.googlegroups.com>

Show all headers | View raw


sinbad <sinbad.sinbad@gmail.com> writes:
> is it ok to allow memcpy () to take size 0;
> or is it a good practice to check for the size
> and do memcpy only for sizes greater than 0;

See section 7.24.1 of the C standard
(http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf is the latest
draft):

    Where an argument declared as size_t n specifies the length of the
    array for a function, n can have the value zero on a call to that
    function.

So yes, it's ok to call memcpy() with a size of 0.

Note that if either s1 or s2 is a null pointer, the behavior is (I
believe) undefined.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
    Will write code for food.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

copy size sinbad <sinbad.sinbad@gmail.com> - 2012-06-07 22:16 -0700
  Re: copy size Keith Thompson <kst-u@mib.org> - 2012-06-07 22:40 -0700
    Re: copy size David T. Ashley <dashley@gmail.com> - 2012-06-08 09:15 -0400
      Re: copy size Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-06-08 09:32 -0400
        Re: copy size David T. Ashley <dashley@gmail.com> - 2012-06-08 09:40 -0400
          Re: copy size Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-06-08 10:31 -0400
          Re: copy size Keith Thompson <kst-u@mib.org> - 2012-06-08 11:53 -0700
          Re: copy size Tim Rentsch <txr@alumni.caltech.edu> - 2012-06-08 12:11 -0700
            Re: copy size "christian.bau" <christian.bau@cbau.wanadoo.co.uk> - 2012-06-08 12:32 -0700
              Re: copy size Tim Rentsch <txr@alumni.caltech.edu> - 2012-06-08 20:42 -0700
      Re: copy size pete <pfiland@mindspring.com> - 2012-06-08 10:30 -0400
      Re: copy size Tim Rentsch <txr@alumni.caltech.edu> - 2012-06-08 11:47 -0700
    Re: copy size pete <pfiland@mindspring.com> - 2012-06-08 10:05 -0400

csiph-web