Bug 10369 - strchr() is implemented as a macro
strchr() is implemented as a macro
Product: Red Hat Linux
Classification: Retired
Component: glibc (Show other bugs)
All Linux
medium Severity medium
: ---
: ---
Assigned To: Cristian Gafton
Depends On:
  Show dependency treegraph
Reported: 2000-03-27 07:01 EST by Kjetil T. Homme
Modified: 2008-05-01 11:37 EDT (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2000-03-27 11:03:23 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description Kjetil T. Homme 2000-03-27 07:01:25 EST
This causes good old K&R code with redundant prototypes to miscompile:

cknfs.c:184: macro `strchr' used without args

These functions need to be inlined instead.

Workaround:  Compile with -g rather than -O.
Comment 1 Bill Nottingham 2000-03-27 11:03:59 EST
It's in the glibc FAQ:

3.8.    I've got errors compiling code that uses certain string
        functions.  Why?

{AJ} glibc 2.1 has special string functions that are faster than the normal
library functions.  Some of the functions are additionally implemented as
inline functions and others as macros.  This might lead to problems with
existing codes but it is explicitly allowed by ISO C.

The optimized string functions are only used when compiling with
optimizations (-O1 or higher).  The behavior can be changed with two feature

* __NO_STRING_INLINES: Don't do any string optimizations.
* __USE_STRING_INLINES: Use assembly language inline functions (might
  increase code size dramatically).

Since some of these string functions are now additionally defined as macros,
code like "char *strncpy();" doesn't work anymore (and is unnecessary, since
<string.h> has the necessary declarations).  Either change your code or

{UD} Another problem in this area is that gcc still has problems on machines
with very few registers (e.g., ix86).  The inline assembler code can require
almost all the registers and the register allocator cannot always handle
this situation.

One can disable the string optimizations selectively.  Instead of writing

        cp = strcpy (foo, "lkj");

one can write

        cp = (strcpy) (foo, "lkj");

This disables the optimization for that specific call.

Note You need to log in before you can comment on or make changes to this bug.