当前位置:C++技术网 > 资讯 > _stricmp函数与stricmp函数

_stricmp函数与stricmp函数

更新时间:2015-11-01 23:32:54浏览次数:1+次

在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里面
我们可以看到如下定义(本文作者注:详细的代码我在我写的《_stricmp函数与stricmp函数小解》一文中,用图片形式凸显了这个函数的定义,方便你查看):


#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的定义,否则就没有。转自CSDN。

在这里本文作者解释下在_stricmp函数与stricmp函数小解》一文中的VC编译器的string.h中函数的定义前都一个_cdecl,这是调用约定,与此函数相同功能的函数有_stdcall,还有就是win32编译时的WINAPI函数。WINAPI在WINDEF.H中被定为:#define WINAPI _stdcall;