comp.lang.ada
 help / color / mirror / Atom feed
From: Florian Weimer <fw@deneb.enyo.de>
Subject: Re: Ada 2012 : aliased parameters ?
Date: Sat, 30 Apr 2011 20:32:04 +0200
Date: 2011-04-30T20:32:04+02:00	[thread overview]
Message-ID: <87y62ra8uz.fsf@mid.deneb.enyo.de> (raw)
In-Reply-To: ipcuof$1rn$1@munin.nbi.dk

* Randy Brukardt:

>> This is unfortunate because it means that this cannot be used to make
>> variadic argument list trick safer and less of a hack.
>
> One could argue that variadic arguments are themselves a hack. :-)

It would make it possible to call this little gem, PostgreSQL's main
client function for executing SQL statements,

   PGresult *PQexecParams(PGconn *conn,
                          const char *command,
                          int nParams,
                          const Oid *paramTypes,
                          const char * const *paramValues,
                          const int *paramLengths,
                          const int *paramFormats,
                          int resultFormat);

without any allocations and in a type-safe manner (for a predefined
set of types).  For such untyped external interfaces, varidic
subprograms are often handy.

> The advantage of the aliased parameters is that they eliminate the runtime 
> checks by forcing the checks to the call site (where they can be statically 
> made 99% of the time).

I'm wondering if it is necessary that the returned limited record is
controlled, so that a reference counter can be incremented and later
decremented to ensure that the access discriminant does not become
dangling.  That would make the whole thing a bit clumsy to use, and
come with quite a bit of run-time overhead.

> The intent is that it is impossible to create a dangling pointer if no 
> unchecked programming is used. (Unchecked_Deallocation, 'Unchecked_Access, 
> Unchecked_Conversion, Address_to_Access_Conversions, abuse of 
> Unchecked_Unions, etc.) That goes for all access types (not just anonymous 
> ones). The problem, of course, is that it is impractical to do much without 
> using one of those things. (I've only succeeded in using 'Access once in one 
> of my programs; in all other cases I had to use 'Unchecked_Access.)

Anonymous access types seem to help quite a bit.  I use 'Access for
access discriminants, creating proxies, to fake the in-out parameter
mode for functions, and on locally defined callback functions.

> (Personally, I prefer to hide pointers as much as possible, as in
> the container cursors, so that dangling pointer detection becomes
> much more possible, and their creation becomes less likely.)

And implicit deference could make them even safer to use.



  reply	other threads:[~2011-04-30 18:32 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-28 11:47 Ada 2012 : aliased parameters ? Yannick Duchêne (Hibou57)
2011-03-28 11:56 ` Dmitry A. Kazakov
2011-03-29  3:04   ` Randy Brukardt
2011-03-28 11:56 ` AdaMagica
2011-03-29 18:22   ` Florian Weimer
2011-03-29 18:34     ` Shark8
2011-03-29 19:35       ` Florian Weimer
2011-03-30  0:12     ` Randy Brukardt
2011-03-29  3:16 ` Randy Brukardt
2011-03-29  7:34   ` Maciej Sobczak
2011-03-30  0:09     ` Randy Brukardt
2011-03-30 19:44       ` Randy Brukardt
2011-04-23 18:47   ` Florian Weimer
2011-04-25  7:19     ` Randy Brukardt
2011-04-28 19:47       ` Florian Weimer
2011-04-28 23:54         ` Randy Brukardt
2011-04-30 18:32           ` Florian Weimer [this message]
2011-04-30 23:46             ` Randy Brukardt
replies disabled

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