Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Andrew Cagney <ac131313@cygnus.com>
To: Fergus Henderson <fjh@cs.mu.oz.au>
Cc: gcc-patches@gcc.gnu.org, gdb-patches@sources.redhat.com,
	binutils@sources.redhat.com
Subject: Re: [rfa] Change lbasename() to return ``const char *''
Date: Wed, 08 Aug 2001 06:35:00 -0000	[thread overview]
Message-ID: <3B71401D.2010409@cygnus.com> (raw)
In-Reply-To: <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


  reply	other threads:[~2001-08-08  6:35 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-08-07 18:06 Andrew Cagney
2001-08-08  5:09 ` Fergus Henderson
2001-08-08  6:35   ` Andrew Cagney [this message]
2001-08-08 10:52 ` Richard Henderson
2001-08-10 16:47   ` Andrew Cagney

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3B71401D.2010409@cygnus.com \
    --to=ac131313@cygnus.com \
    --cc=binutils@sources.redhat.com \
    --cc=fjh@cs.mu.oz.au \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=gdb-patches@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox