What is strdup() supposed to do? Does anyone have a copy?

Robert E. Lancia rob at meaddata.com
Sat Feb 23 04:55:30 AEST 1991


>>>>> dag at persoft.com (Daniel Glasser) writes:

Daniel>Nit #2: You should simplify your expression in the "malloc()", that is,
Daniel>		sizeof(char) * strlen(foo) + sizeof(char)
Daniel>	  could be written
Daniel>		sizeof(char) * (strlen(foo) + 1)


>>>>> jeff at onion.rain.com (Jeff Beadles) then said:

Jeff> Untrue.  What if sizeof(char) != 1?  Yours will break, and mine
Jeff> will work.


>>>>> fischer at iesd.auc.dk (Lars P. Fischer) then writes:

Lars> Gimme a break. Are you going to tell us that
Lars> A * (B + 1) != A * B + A
Lars> for A != 1 ?? If you can't handle basic arithmetic, what makes you
Lars> think you can write a C program?


I think Lars might have jumped the gun a bit here.  Maybe, just MAYBE, Jeff
mis-read Daniel's rewrite as

    sizeof(char) * strlen(foo) + 1

instead of (the correct)

    sizeof(char) * (strlen(foo) + 1)

If this were the case, his comment makes perfect sense.  Regardless, I'm
giving Jeff the benefit of the doubt and blaming his eye doctor! :^)
--
|Robert Lancia                  |  I have a split   |  Mead Data Central
|(513) 297-2560                 |  personality, and |  Data Services Division
|rob at pmserv.meaddata.com        |  these are HIS    |  P.O. Box 308
|...!uunet!meaddata!pmserv!rob  |  comments.        |  Dayton, Ohio  45401



More information about the Comp.lang.c mailing list