I have a little C program that uses _stricmp():
#include <stdio.h>
#include <string.h>
int main()
{
printf("%d\n", _stricmp("abc", "ABC"));
return 0;
}
When I compiled it with -O2 (inlining enabled), it works fine.
zby@winxp-vbox /c/src
$ gcc -O2 test.c
zby@winxp-vbox /c/src
$ ./a.exe
0
But when I compiled it with -O0 (optimizing disabled), it generated a warning.
zby@winxp-vbox /c/src
$ gcc -O0 test.c
test.c: In function 'main':
test.c:5:17: warning: implicit declaration of function '_stricmp' [-Wimplicit-fu
nction-declaration]
printf("%d\n", _stricmp("abc", "ABC"));
^
zby@winxp-vbox /c/src
$ ./a.exe
0
Although the program still runs without any problems, the warning should not be generated.
I think the problem is there should not have "defined __NO_INLINE__" in the #if statment in the strings.h header, but I'm not sure.
Here are my system information:
zby@winxp-vbox /c/src
$ gcc -v
Using built-in specs.
COLLECT_GCC=C:\MinGW\bin\gcc.exe
COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/mingw32/5.3.0/lto-wrapper.exe
Target: mingw32
Configured with: ../src/gcc-5.3.0/configure --build=x86_64-pc-linux-gnu --host=m
ingw32 --prefix=/mingw --disable-win32-registry --target=mingw32 --with-arch=i58
6 --enable-languages=c,c++,objc,obj-c++,fortran,ada --enable-static --enable-sha
red --enable-threads=posix --with-dwarf2 --disable-sjlj-exceptions --enable-vers
ion-specific-runtime-libs --enable-libstdcxx-debug --with-tune=generic --enable-
libgomp --disable-libvtv --enable-nls
Thread model: posix
gcc version 5.3.0 (GCC)
zby@winxp-vbox /c/src
$ ld -v
GNU ld (GNU Binutils) 2.25.1
zby@winxp-vbox /c/src
$ uname -a
MINGW32_NT-5.1 WINXP-VBOX 1.0.19(0.48/3/2) 2016-07-13 17:45 i686 Msys
Oh, I'm sorry, the previous patch won't work, the #if and #endif should be totally removed.
Here is the fixed patch.
Thanks for the report. The logic surrounding the
_stricmp()and_strnicmp()declarations is clearly wrong, but unfortunately, neither of your patches is entirely adequate to correct it.The correct logic is:
*
<strings.h>does not need either of these declarations, if__NO_INLINE__is defined, (possibly implicitly, by the compiler); however, as you've noted, we still need to declare them, because<string.h>may need to expose them. However...*
<string.h>should not expose them, if__STRICT_ANSI__is defined, but<strings.h>may still need them, regardless of__STRICT_ANSI__, if__NO_INLINE__is not defined.Thus, the appropriate logic is to always declare them, as your second patch does, unless
__STRICT_ANSI__and__NO_INLINE__are both defined; your patch omits the latter exclusion, which is appropriately addressed by my attached alternative patch. Please test it.Last edit: Keith Marshall 2017-01-10
Diff:
I committed [66c389].
Related
Commit: [66c389]