stricmp和_stricmp

來源:互聯網
上載者:User

在msdn裡面(http://msdn.microsoft.com/en-us/library/ms235365(VS.80).aspx)有這麼一段話:

These POSIX functions are deprecated beginning in Visual C++ 2005. Use the ISO C++ conformant_stricmp, _wcsicmp, _mbsicmp, _stricmp_l, _wcsicmp_l, _mbsicmp_l instead.

意思是在Visual C++ 2005以後,stricmp, wcsicmp被_stricmp, _wcsicmp, _mbsicmp, _stricmp_l, _wcsicmp_l, _mbsicmp_l等替代了。

我在編譯libidn的時候,發現在命令列裡面連結時會出現錯誤:

libidn.lib(idna.obj) : error LNK2019: unresolved external symbol __imp__stricmp
referenced in function _idna_to_unicode_internal

而這句話在vs 2005 ide裡面卻不會出現。

但我把libidn-1.9/win32/include/config.h裡面的

#define strcasecmp stricmp
#define strncasecmp strnicmp

改為:

#define strcasecmp _stricmp
#define strncasecmp _strnicmp

就都沒有問題了。我就奇怪了,為什麼會出現這種問題?為什麼有的時候有stricmp,而有的時候沒有stricmp呢?

stricmp,_stricmp的定義在E:/Program Files/Microsoft Visual Studio 8/VC/include/string.h裡面,

我們可以看到如下定義:

#if     !__STDC__

....................

/* prototypes for oldnames.lib functions */
_CRT_NONSTDC_DEPRECATE(_strcmpi) _CRTIMP __checkReturn int __cdecl strcmpi(__in_z const char * _Str1, __in_z const char * _Str2);
_CRT_NONSTDC_DEPRECATE(_stricmp) _CRTIMP __checkReturn int __cdecl stricmp(__in_z const char * _Str1, __in_z const char * _Str2);
_CRT_NONSTDC_DEPRECATE(_strlwr) _CRTIMP char * __cdecl strlwr(__inout_z char * _Str);
_CRT_NONSTDC_DEPRECATE(_strnicmp) _CRTIMP __checkReturn int __cdecl strnicmp(__in_z const char * _Str1, __in_z const char * _Str, __in size_t _MaxCount);
_CRT_NONSTDC_DEPRECATE(_strnset) _CRTIMP char * __cdecl strnset(__inout_ecount_z(_MaxCount) char * _Str, __in int _Val, __in size_t _MaxCount);
_CRT_NONSTDC_DEPRECATE(_strrev) _CRTIMP char * __cdecl strrev(__inout_z char * _Str);
_CRT_NONSTDC_DEPRECATE(_strset)         char * __cdecl strset(__inout_z char * _Str, __in int _Val);
_CRT_NONSTDC_DEPRECATE(_strupr) _CRTIMP char * __cdecl strupr(__inout_z char * _Str);

#endif  /* !__STDC__ */

從上面可以看出,如果__STDC__ 為0,則會有stricmp的定義,否則就沒有。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.