binutils Newspaper
NOVEMBER 30, 2026
binutils/rclex — Proposed

binutils/rclex: fix -Wincompatible-pointer-types-discards-qualifiers warning

Fix pointer type warning in binutils/rclex.c by using a const char pointer.

Simon Marchi is addressing a compiler warning in binutils/rclex.c related to assigning const char * to char *. This warning arises because glibc 2.43 onwards makes strchr return a const char * when given a const char *. The patch introduces a new const char *quote variable to store the result of strchr, preventing the qualifier discard and resolving the warning.

In the Thread 1 participant
  1. Simon Marchi proposer

    Proposes fixing a pointer type warning in `binutils/rclex.c` by correctly handling `const` qualifiers.

    “Building binutils with glibc 2.43 or later gives: /home/smarchi/src/binutils-gdb/binutils/rclex.c:218:8: warning: assigning to 'char *' from 'const char *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers] Since glibc 2.43, strchr returns a pointer to const when passed a pointer to const. The result is assigned to `send`, which needs to stay non-const because it is als…”

In Details

This patch addresses a compiler warning in binutils/rclex.c related to pointer type compatibility, specifically -Wincompatible-pointer-types-discards-qualifiers. The warning occurs because strchr in recent glibc versions returns const char * when operating on const char * input. The code assigns this to char *send, discarding the const qualifier. The fix introduces a new const char *quote variable to hold the result of strchr, preserving the const qualifier and avoiding the warning. The original send variable is still used for the non-const operation with strtol.

For Context
rclex.c
A C source file containing a lexer for parsing resource compiler directives.
glibc 2.43
Version 2.43 of the GNU C Library, a widely used C standard library for Linux and other Unix-like systems.
strchr
A C standard library function that searches for the first occurrence of a character within a string.
const char *
A pointer to a character that cannot be modified through the pointer.
char *
A pointer to a character that can be modified through the pointer.
-Wincompatible-pointer-types-discards-qualifiers
A compiler warning flag that flags assignments between pointer types where a 'const' qualifier is discarded.
Filed Under: warningsglibclexerconst correctness