Amir Saniyan Amir Saniyan - 7 months ago 93
C Question

strdup or _strdup?

When I use

in Microsoft Visual C++, it warns me:

warning C4996: 'strdup': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _strdup. See online help for details.

Thus it seems
is correct.

But when I use
in GCC (Fedora Linux OS), the compiler shows an error:

error: ‘_strdup’ was not declared in this scope

With GCC and Linux, compiler does not show any error for

Which is correct -

Note: I include
in my code.


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.