stricmp和_stricmp

stricmp与_stricmp的区别及使用注意事项
在Visual C++ 2005之后,stricmp等POSIX函数被弃用,推荐使用_stricmp等ISO C++兼容的函数。在编译libidn时遇到链接错误,发现将strcasecmp和strncasecmp替换为_stricmp和_strnicmp可以解决问题。stricmp的定义取决于宏__STDC__,当其为0时,stricmp会被定义。

在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的定义,否则就没有。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值