Re: [PATCH] git-compat-util: Avoid strcasecmp() being inlined
- From
Sebastian Schuberth <sschuberth@gmail.com>
- Date
- Sep 12, 2013, 19:46 UTC
- Message-ID
- <CAHGBnuPzzokV7YMrx0gAL1VACcmaLwFoaB3n6bX8Y-UDHs7S8A@mail.gmail.com>
- In-Reply-To
- <20130912182057.GB32069@sigill.intra.peff.net>
On Thu, Sep 12, 2013 at 8:20 PM, Jeff King <peff@peff.net> wrote:
Show 16 quoted lines
>> > I wonder if GCC has changed it's behaviour to more closely match C99. >> > Clang as a compatibility article about this sort of issue: >> > >> > http://clang.llvm.org/compatibility.html#inline >> >> Interesting. The ways the page suggests as fixes are >> >> - change it to a "statis inline"; >> - remove "inline" from the definition; >> - provide an external (non-inline) def somewhere else; >> - compile with gnu899 dialect. > > Right, option 3 seems perfectly reasonable to me, as we must be prepared > to cope with a decision not to inline the function, and there has to be > _some_ linked implementation. But shouldn't libc be providing an > external, linkable strcasecmp in this case?
MinGW / GCC is not linking against libc, but against MSVCRT, Visual Studio's C runtime. And in fact MSVCRT has a non-inline implementation of a "case-insensitive string comparison for up to the first n characters"; it just happens to be called "_strnicmp", not "strncasecmp". Which is why I still think just having a "#define strncasecmp _strnicmp" is the most elegant solution to the problem. And that's exactly what defining __NO_INLINE__ does. Granted, defining __NO_INLINE__ in the scope of string.h will also add a "#define strcasecmp _stricmp"; but despite it's name, defining __NO_INLINE__ does not imply a performance hit due to functions not being inlined because it's just the "strncasecmp" wrapper around "_strnicmp" that's being inlined, not "_strnicmp" itself.
-- Sebastian Schuberth