comp.lang.ada
 help / color / mirror / Atom feed
From: "REH" <me@you.com>
Subject: Re: aliased and parameters
Date: Tue, 01 Aug 2006 02:28:40 GMT
Date: 2006-08-01T02:28:40+00:00	[thread overview]
Message-ID: <s%yzg.11536$8j3.1245@twister.nyroc.rr.com> (raw)
In-Reply-To: N9yzg.111006$1i1.103407@attbi_s72


"Jeffrey R. Carter" <spam.not.jrcarter@acm.not.spam.org> wrote in message 
news:N9yzg.111006$1i1.103407@attbi_s72...
> REH wrote:
>>
>> Thanks Jeff.  recv is the standard POSIX (or BSD) socket receive
>> function.  It takes a pointer.  Yes, I could use an array (as I could
>> still map it to a C pointer).  The problem with this is I either have
>> to move the data from its "normal" type into the array (excessive data
>> movement) or I have to map the array over top of my data (which gets us
>> right back to using 'Address).
>
> I was referring to the Ada library, not the C library (in this case). 
> There is, for example, a standard Ada binding to POSIX. Are you using it, 
> or are you making your own binding? If the latter, you should probably 
> consider the former. You might also want to look into AdaSockets, which is 
> a fairly platform-independent binding to sockets.

I wasn't aware there was a standard binding.  I am using some binding for 
Integrity that GHS has in their examples, but I was plaining on modifying 
them with better typing.

>
> In any case, System.Address is not a pointer. There are compilers where a 
> pointer and an Address are the same; there are others where they are 
> different. If portability is an issue, you should not pass an address.

I know that, thanks.  The reason I am using Address (and the ONLY time I use 
it) is situation where I need a generic pointer (and I am using a system 
where it maps correctly to C pointers) and am talking to C.  Such situation 
as a send or receive of raw data over a transport such as sockets.  I didn't 
want to have to define a binding for every type I need to send/receive, but 
it looks like it may be my own way around my issue (nor do I want to have to 
instantiate one everytime from a generic).  I never use address within Ada, 
but sometimes it seems to be the cleanest way to talk to the OS.  At least 
it was with '83.  '95's new aliasing rules threw a monkey wrench into that 
(though, I know it's for the better).  Also, binding are fine for the types 
I know about, but my group provides middleware for the applications.  Part 
of the middleware is bindings to the OS.  For sockets and such that can and 
do send any type of data, Address seems cleaner than forcing them to 
instanitate the call for every type they send with sockets (which--knowing 
them--they would probably balk at).  But at least in that situation, the 
compiler will complain to *them* that they are taking the address of 
non-aliased and non-volatile variables!

Too bad Ada doesn't have a generic access type, just for talking with C. 
That would force any variable used to be aliased, avoid any portability 
issues with using Address for pointers, and without a proliferation of 
multiple binding and/or instantiations.


>
> Using an address to achieve an overlay is a different matter. This is a 
> perfectly portable use of addresses, but not one that is recommended.
>
Tell that to GHS.  Their compiler is raising havoc with the application 
group's overlays, even rep. spec'd ones!  Oh well, serves 'em right for 
doing such a thing.

> If you are building your own binding (probably not a good idea), then you 
> can import the function using an out mode parameter of the desired type, 
> as suggested elsewhere. If, as is likely, you need to receive many 
> different types, you can write a generic to create the bindings.

Well, whether or not it's a good idea is moot.  None exist to talk to our 
BSP or OS.  So, I have to write them.  Which is fine.  It's not hard.  I've 
had to do it with many system.  The only problem I've every had was the 
above, and only with one compiler.

REH





      reply	other threads:[~2006-08-01  2:28 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-07-31 18:05 aliased and parameters REH
2006-07-31 18:37 ` Jeffrey R. Carter
2006-07-31 19:02   ` REH
     [not found]     ` <1154373046.777655.292010@m79g2000cwm.googlegroups.com>
2006-07-31 19:26       ` REH
2006-07-31 19:59         ` REH
2006-07-31 21:52     ` Björn Persson
2006-08-01  0:35       ` REH
2006-08-01  1:31     ` Jeffrey R. Carter
2006-08-01  2:28       ` REH [this message]
replies disabled

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