Re: Problem in Strdup()



pete <pfiland@xxxxxxxxxxxxxx> writes:

> Tim Rentsch wrote:
> >
> > pete <pfiland@xxxxxxxxxxxxxx> writes:
> >
> > > Tim Rentsch wrote:
> > > >
> > > > Keith Thompson <kst-u@xxxxxxx> writes:
> > >
> > > > > How about this?
> > > > >
> > > > > char *dupstr(const char *src)
> > > > > {
> > > > > char *p = malloc(strlen(src) + 1);
> > > > > if (p != NULL) {
> > > > > strcpy(p, src);
> > > > > }
> > > > > return p;
> > > > > }
> > > >
> > > > char *dupstr(const char *src)
> > > > {
> > > > char *p = malloc(strlen(src) + 1);
> > > >
> > > > return p ? strcpy(p,src) : 0;
> > > > }
> > >
> > > I like Keith's better.
> >
> > That's all well and good, but what qualities allow
> > the first to be judged better than the second?
> > What is your metric?
>
> Keith's is simpler.

Is this some objective metric that you're applying,
or just your personal subjective metric? Most of
the metrics I'm used to would rank the second
definition as simpler.
.



Relevant Pages

  • Re: Problem in Strdup()
    ... >> Tim Rentsch wrote: ... >>> That's all well and good, but what qualities allow ... > the metrics I'm used to would rank the second ... Prev by Date: ...
    (comp.lang.c)
  • Re: Problem in Strdup()
    ... >> Tim Rentsch wrote: ... > That's all well and good, but what qualities allow ... Prev by Date: ...
    (comp.lang.c)