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

Guy Harris guy at auspex.auspex.com
Wed Feb 20 05:54:04 AEST 1991


>   A creature of habit, I suppose.  I've been bitten too often when I return
>   something from a function that isn't static.  (int's, for example.)  For
>   this case, it really doesn't matter.
>
>I would suggest that if you can't tell the difference between a value
>that is safe to return from a function, and a value that is not,
>you're better off letting other people post code to the net.

Yup.  I'm really curious how the poster to whom you're responding had
gotten bitten by returning a non-static "int"; other code does so
successfully all the time.  The place where you tend to get bitten is
when you return a pointer *to* something that's not static, not when you
return something that's not static....

>   Untrue.  What if sizeof(char) != 1?  Yours will break, and mine will work.
>
>You're wrong.  Both expressions above will result in the proper value,
>whether sizeof(char) is 1 or not.

And, on top of that, to quote the ANSI C standard:

	   When applied to an operand that has type "char", "unsigned
	char", or "signed char", (or a qualified version thereof) the
	result is 1.



More information about the Comp.lang.c mailing list