From: Daniel Jacobowitz <drow@mvista.com>
To: Klee Dienes <kdienes@apple.com>
Cc: gdb-patches@sources.redhat.com
Subject: Re: [RFA] Function return type checking
Date: Tue, 05 Feb 2002 08:07:00 -0000 [thread overview]
Message-ID: <20020205110722.A24325@nevyn.them.org> (raw)
In-Reply-To: <DC23F3D0-1A1B-11D6-BA6D-0030653FA4C6@apple.com>
On Tue, Feb 05, 2002 at 01:36:41AM -0800, Klee Dienes wrote:
> (This is basically the same patch I sent last week, just updated
> to the latest source base.)
>
> The following patch adds "expected return type" support to the target
> function call interface. The "expected return type" is specified
> using cast syntax; it is ignored if actual type information for the
> function is available. If no type information is provided for a
> function, the user is now required to provide an expected return type
> using the cast syntax, or get an error.
Having thought about this since you last posted it, I don't really like
it. What you do by overloading the cast syntax for this operation is
very ``cute'', but exceedingly unintuitive.
> Some examples:
>
> (gdb) print fabs (3.0) (no type information present)
> Unable to call function at 0x%lx: no return type information available.
> To call this function anyway, you can cast the return type explicitly
> (e.g. 'print (float) fabs (3.0)').
Except for the syntax of the example, I like this message. This is a
good message. We need more warnings about doing things like this.
Fabs is a bad example, though - can I suggest you look over the list of
what GCC defines as builtin functions, and not choose one?
> The reason I suggest 2) might be controversial is that the old
> behavior can be convenient in the general case. A lot of functions
> *do* return int, and when debugging programs without symbols, it can
> be annoying to have to declare the return type, just to make the rare
> case when functions return floats/structs behave correctly. But I'd
> argue that it's not *that* big a deal to cast a return value, and
> correctness must always take priority.
Losing the implicit int doesn't bother me especially.
Have you considered casting the function itself? Something like:
(gdb) print ((float (*)(float)) fabs) (3.0)
$1 = 3.0
(gdb) set fabs
Which, I will note, already works except for the fact that we neglect
the argument types on function pointers. Or
(gdb) set $fabs = (float (*)(float)) fabs
(gdb) p $fabs(4.0)
$2 = 4.0
Which works with the same caveat.
Specifying just the return type of the function is not useful in the
general case. If we do not understand the argument types, it will
still crash. I was trying to find an example where float vs. double
would cause a problem too, but I can't think of one at the moment.
There's one in the testsuite though, for some targets.
--
Daniel Jacobowitz Carnegie Mellon University
MontaVista Software Debian GNU/Linux Developer
next prev parent reply other threads:[~2002-02-05 16:07 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-02-05 1:36 Klee Dienes
2002-02-05 3:24 ` Eli Zaretskii
2002-02-05 8:07 ` Daniel Jacobowitz [this message]
2002-02-06 13:43 ` Klee Dienes
2002-02-06 14:14 ` Daniel Jacobowitz
2002-03-09 20:30 ` Andrew Cagney
2002-03-12 2:38 ` Klee Dienes
2002-03-12 7:56 ` Andrew Cagney
2002-03-12 10:08 ` Klee Dienes
2002-03-12 10:34 ` Andrew Cagney
2002-02-08 13:41 ` Kevin Buettner
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=20020205110722.A24325@nevyn.them.org \
--to=drow@mvista.com \
--cc=gdb-patches@sources.redhat.com \
--cc=kdienes@apple.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