strdup or _strdup?
Solution 1:
Which is correct?
strdup
is a perfectly correct POSIX function. Nevertheless, it doesn't belong to the standard, and the ANSI C standard reserves some (broad) classes of function names for further use. Among these, there are
- Function names that begin with str and a lowercase letter
therefore, the MS guys decided to replace strdup
with _strdup
.
I'd just continue using strdup
. It's unlikely the C committee will define strdup
to something else than POSIX. Either #define strdup _strdup
or silence the warning.
BTW I hope you see this applies to your functions with names like string_list
etc., too.
Solution 2:
strdup
is not a standard C++ function. but it is apparently a Posix function, and anyway it's a well known function which has been there since K&R C. so if you absolutely must use it, do not fret about any possible name collision, and just write strdup
for maximum portability.