bug-gnulib
[Top][All Lists]
Advanced

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

[bug-gnulib] Re: [PATCH]: fix warning in the hash module


From: Yoann Vandoorselaere
Subject: [bug-gnulib] Re: [PATCH]: fix warning in the hash module
Date: Tue, 17 May 2005 15:26:52 +0200

On Tue, 2005-05-17 at 14:21 +0200, Jim Meyering wrote:
> Yoann Vandoorselaere <address@hidden> wrote:
> >> > This patch fix constness warning in the GnuLib hash module.
> 
> That patch fixes three of the four warnings produced by gcc -Wcast-qual.
> The final one is here:
> 
>   void *
>   hash_insert (Hash_table *table, const void *entry)
>   {
>     ...
> 
>     return (void *) entry;          <<<=======
>   }
> 
> What's the gain in fixing three of them if one still remains?

This warning can be fixed the same way I fixed the other (using the
union). It was a proof of concept patch.

> That last one looks unavoidable, given my requirement that the
> second parameter retain the `const' attribute.

This requirement is technically wrong since you allow modification of
the input argument through the user provided callback.

Additionally, the last warning is not unavoidable, you can adapt the
union patch to fix up this problem (but I still maintain that you should
not use const at all).

> FYI, there are similar const-removing casts in many other modules.
> Look at all of the functions like memchr, memmem, strdup, etc.,
> that take a const string and return a non-const pointer into that
> same string.

- strdup return a copy of the string. It's expected it won't return a
const.

- memmem, memchr, strstr, and such don't modify the input argument. It
is thus normal they use the const keyword. And they should not return a
const since they don't know if the user used a const argument or not as
the input.

The point is that you modify the input argument through the delete
callback... So you should probably not be using const.

-- 
Yoann Vandoorselaere <address@hidden>





reply via email to

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