This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [rfa] Change lbasename() to return ``const char *''
- To: Fergus Henderson <fjh at cs dot mu dot oz dot au>
- Subject: Re: [rfa] Change lbasename() to return ``const char *''
- From: Andrew Cagney <ac131313 at cygnus dot com>
- Date: Wed, 08 Aug 2001 09:35:25 -0400
- Cc: gcc-patches at gcc dot gnu dot org, gdb-patches at sources dot redhat dot com,binutils at sources dot redhat dot com
- References: <3B709080.7040508@cygnus.com> <20010808220910.A8080@murlibobo.cs.mu.OZ.AU>
> On 07-Aug-2001, Andrew Cagney <ac131313@cygnus.com> wrote:
>
>> The attached patch changes the liberty function lbasename() so that it
>> returns ``const char *''.
>
>
> Why? That will lead to the need for casts in the callers. Why not just
> put the cast in lbasename(), like is done for strchr() in the C standard?
(This was discussed once before as an RFC :-).
Why not? At present lbasename() throws away information. The thing to
remember is that lbasename() is ment to be kind of like basename() and
other (botched?) ISO/POSIX library funtions, only useful :-)
If someone really wants to blat the returned buffer let that be made
_explicit_ at the callers end. Better still, use:
xstrdup (lbasename (...))
which gives well defined semantics.
> lbasename() is const-polymorphic, i.e. the return value should be
> a const pointer iff the argument is a const pointer.
> C doesn't have any good way to express the type of const-polymorphic routines.
> Unless you duplicate the code in two functions, one for const pointers and one
> for non-const pointers, some casting will be required.
I've been through all the callers and I didn't find a single places
where a cast was needed.
enjoy,
Andrew