[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug-grep] PARAMS, gnulib update and const

From: Paul Eggert
Subject: Re: [bug-grep] PARAMS, gnulib update and const
Date: Mon, 21 Mar 2005 11:08:40 -0800
User-agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.4 (gnu/linux)

Claudio Fontana <address@hidden> writes:

> Yeah, the problem is that it is a declaration of
> intent, that if violated (and it is),

Can you give some sample violations in the GNU grep source code?
If the intent is violated, then that can cause real bugs in some cases,
since compilers are entitled to assume that "const" is not violated.

One problem with "const" that is inherent to the current C design is
prototypes like this:

   char *strchr (char const *str, int ch);

The implementation of strchr must cast "char const *" to "char *", and
this is a botch in C.  However, it does not violate the C standard, so
long as the caller never attempts to use this to convert "char const *"
to "char *".

Casts must be used to attack this sort of problem, and this does not
necessarily indicate a violation or a bug in the program.  However, in
my experience most other casts of "char const *" to "char *" indicate
a real problem in the code.

These days I try to write C code without any casts whatsoever.
strchr-implementation-like casts are one of the rare exceptions.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]