[go: up one dir, main page]

Menu

#2322 _stricmp() is not declared when inline is disabled

WSL
closed
None
Bug
fixed
IINR_-_Include_In_Next_Release
True
2017-01-24
2016-11-26
zhangboyang
No

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
1 Attachments

Discussion

  • zhangboyang

    zhangboyang - 2016-11-26

    Oh, I'm sorry, the previous patch won't work, the #if and #endif should be totally removed.
    Here is the fixed patch.

     
  • Keith Marshall

    Keith Marshall - 2017-01-10

    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
  • Keith Marshall

    Keith Marshall - 2017-01-10
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -1,5 +1,5 @@
    -I have a little C program that uses _stricmp()
    -~~~
    +I have a little C program that uses `_stricmp()`:
    +~~~~
     #include <stdio.h>
     #include <string.h>
     int main()
    @@ -7,20 +7,20 @@
        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':
    @@ -32,13 +32,14 @@
     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.
    +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.
    @@ -61,4 +62,4 @@
     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
    -~~~
    +~~~~
    
    • status: unread --> pending
    • assigned_to: Keith Marshall
    • Category: Unknown --> IINR_-_Include_In_Next_Release
     
  • Keith Marshall

    Keith Marshall - 2017-01-24
    • status: pending --> closed
    • Resolution: none --> fixed