strdup or _strdup?

后端 未结 7 2092
我寻月下人不归
我寻月下人不归 2020-12-01 04:05

When I use strdup in Microsoft Visual C++, it warns me:

warning C4996: \'strdup\': The POSIX name for this item is deprecated. Instead, u

7条回答
  •  抹茶落季
    2020-12-01 04:47

    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.

提交回复
热议问题