comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Ada Procedure Parameters That Use the Plus Sign
Date: Fri, 12 Jun 2015 10:00:47 +0200
Date: 2015-06-12T10:00:47+02:00	[thread overview]
Message-ID: <6p8ml2yn7z6m.168scgt6xcuc2.dlg@40tude.net> (raw)
In-Reply-To: b3779aef-43d6-4186-8de5-814346f2ab0e@googlegroups.com

On Thu, 11 Jun 2015 10:24:45 -0700 (PDT), NiGHTS wrote:

> I recently stumbled across some Ada code that appends a plus sign in front
> of a parameter name of a function or procedure call. From the context it
> seems like it is doing a forced cast between two incompatible types. 

Compatible types actually.
 
> Here is one example I found in the AdaGtk demo create_tree_view.adb line 243:
> 
> Gtk_New (Tree, +Model);
> 
> My questions are:
> 
> 1. What is this called? Is there a name for this?

In this case it is a downcast, I believe.

> 2. What exactly is happening here?

A concrete tree model is converted to the model interface. There is no
physical conversion, of course, just a reference object is converted to
another reference object. Thus from the language POV it is a conversion,
from the GTK's POV it is not.

> 3. Is it safe? Should it be avoided?

It is safe, though a quite lot irritating.

> 4. Is there another way to accomplish this without the use of '+' ?

In this concrete case there is no other way (I mean without an explicit
call) because Ada lacks the sort of MI/subtyping which would be required
for this.

In GtkAda, I think (too lazy to look), you could also use To_Interface
instead:

   Gtk_New (Tree, To_Interface (Model));

which is just same, but looks better and cleaner.

> 5. Where can I find out more about this?

Ada reference manual, GtkAda reference?

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de


  parent reply	other threads:[~2015-06-12  8:00 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-11 17:24 Ada Procedure Parameters That Use the Plus Sign NiGHTS
2015-06-11 17:36 ` David Botton
2015-06-11 18:21   ` NiGHTS
2015-06-11 18:52     ` David Botton
2015-06-12  8:00 ` Dmitry A. Kazakov [this message]
2015-06-12  8:45 ` Jacob Sparre Andersen
2015-06-12 15:19 ` NiGHTS
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox