Bug 10369 - strchr() is implemented as a macro
Summary: strchr() is implemented as a macro
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: glibc   
(Show other bugs)
Version: 6.1
Hardware: All
OS: Linux
Target Milestone: ---
Assignee: Cristian Gafton
QA Contact:
Depends On:
TreeView+ depends on / blocked
Reported: 2000-03-27 12:01 UTC by Kjetil T. Homme
Modified: 2008-05-01 15:37 UTC (History)
0 users

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

Attachments (Terms of Use)

Description Kjetil T. Homme 2000-03-27 12:01:25 UTC
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 16:03:59 UTC
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.