Xref: utzoo comp.sources.wanted:15382 alt.sources.wanted:953 comp.lang.c:36373 Path: utzoo!utgpu!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!crdgw1!camelback!volpe From: volpe@camelback.crd.ge.com (Christopher R Volpe) Newsgroups: comp.sources.wanted,alt.sources.wanted,comp.lang.c Subject: Re: What is strdup() supposed to do? Does anyone have a copy? Message-ID: <16988@crdgw1.crd.ge.com> Date: 21 Feb 91 13:33:10 GMT References: <1991Feb17.045913.17126@sbcs.sunysb.edu> Sender: news@crdgw1.crd.ge.com Reply-To: volpe@camelback.crd.ge.com (Christopher R Volpe) Followup-To: comp.sources.wanted Lines: 51 In article , fischer@iesd.auc.dk (Lars P. Fischer) writes: |>>>>>> dag@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) ^ |-This paren isn't closed, and may be causing much of the confusion. |> |>>>>>> jeff@onion.rain.com (Jeff Beadles) then said: |> |>Jeff> Untrue. What if sizeof(char) != 1? Yours will break, and mine |>Jeff> will work. |> |>Gimme a break. Are you going to tell us that |> |> A * (B + 1) != A * B + A |> |>for A != 1 ?? If you can't handle basic arithmetic, what makes you |>think you can write a C program? I think Lars and Jeff are talking about different expressions here, due to the missing closing parenthesis. Jeff saw the expression sizeof(char) * strlen(foo) + 1 (he didn't see the '(' before 'strlen') and noted that this wouldn't be equal to sizeof(char) * strlen(foo) + sizeof(char) in the event that sizeof(char) != 1. This is absolutely true, but a moot point since sizeof(char) == 1 by definition. However, Lars saw the expression sizeof(char) * (strlen(foo) + 1) (he added the missing paren) and noted that this is equal to sizeof(char) * strlen(foo) + sizeof(char) by mathematical identity (distribution of multiplication over addition) regardless of whether or not sizeof(char) == 1. The non-expression originally posted by Daniel, however, was not what either of them saw, and they each extrapolated in different directions to arrive at what they thought Daniel intended to write. I hope this clears up the confusion. -Chris ================== Chris Volpe G.E. Corporate R&D volpecr@crd.ge.com