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


Groups > comp.lang.c > #21954

Re: copy size

From David T. Ashley <dashley@gmail.com>
Newsgroups comp.lang.c
Subject Re: copy size
Date 2012-06-08 09:40 -0400
Message-ID <m104t7hdkrifgikal6mo9a1n6lphpb60of@4ax.com> (permalink)
References <03c3ed4d-f3ce-437b-9476-1c512c7772de@o3g2000pby.googlegroups.com> <lnehpqcqe3.fsf@nuthaus.mib.org> <o5u3t7t3os1rvojjgtihk67bmhnlt5eqc7@4ax.com> <jqsutq$2hn$1@dont-email.me>

Show all headers | View raw


On Fri, 08 Jun 2012 09:32:34 -0400, Eric Sosman
<esosman@ieee-dot-org.invalid> wrote:

>> b)Allowing memcpy(dptr, sptr, 0) means that you decided to push logic
>> to handle the size=0 case down into the function, by definition.  It
>> could just as easily be handled by the caller.  In some programs, the
>> case of size=0 and an invalid pointer go together.  It seems useful to
>> make it standard that if size=0, neither pointer will be dereferenced.
>
>     This seems self-contradictory.  If the caller can handle a
>special case "just as easily," why is it "useful" to require the
>internals of memcpy() to handle it in a particular way?

Please don't play Devil's Advocate because you are bored  : ).

Creating a memcpy() function that doesn't handle the size=0 case is
just as silly as creating a square root function that calculates
square root for every non-negative integer except 0.

It forces the users to either a)wrap the function or b)handle the
exception case many times whereas handling it in the function would
require handling it only once.

DTA

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