comp.lang.ada
 help / color / mirror / Atom feed
* Re: Ada95 Streams Question
@ 1996-06-23  0:00 Robert Dewar
  1996-06-24  0:00 ` michael
  0 siblings, 1 reply; 17+ messages in thread
From: Robert Dewar @ 1996-06-23  0:00 UTC (permalink / raw)



"I have connected an Ada95 executable to a C++ executable using streams. The Ada
is the brains of the application, and the C++ is the Motif pretty face. On both
sides I have defined a set of portable types which application types are
converted to for transmission and converted from on receipt."

This should work reasonably reliably with GNAT, cannot say for other
Ada 95 compilers which might do something completely different for
stream rerpresentations of primitive data.

It is a bit of a puzzle to us why you don't just use a procedural
interface. It would be MUCH more portable, and MUCH more efficient




^ permalink raw reply	[flat|nested] 17+ messages in thread
* Re: Ada95 Streams Question
@ 1996-06-24  0:00 Chris.Morgan
  0 siblings, 0 replies; 17+ messages in thread
From: Chris.Morgan @ 1996-06-24  0:00 UTC (permalink / raw)



Samuel wrote :

>To be general, Ada compilers are free to use any representation of
>streams. One may well choose raw conversions (as GNAT does) while
>another one will adopt XDR encoding.
>

(Please note. My comments below apply to my particular case - using streams
between different processes on the same machine running Solaris.)

This is a good point. However if a compiler took the trouble of offering XDR,
it would presumably document this, and perhaps offer raw streams as well (maybe
with a configuration pragma since they seem, to me, the easiest to support).
Either way, the C++ can again be connected up quite straightforwardly (since
XDR is a natural format for network transfer, I'm sure C++ can be made to read
that in preference to raw data).

It seems to me that yes, in principle what I'm doing is not portable, but it is
unlikely to break when connecting Ada to C++ on comparable platforms, whatever
the version of GNAT. For another compiler it would either work the same, or
some other easily understood way. What I would be surprised by is if an Ada
stream were some new entity with unknown internal structure (neither ASCII, nor
raw binary, nor XDR etc). Why would anyone bother when the Unix (Solaris)
streams facility is already a large superset of the whole Ada Streams concept?

That I think is the root of my question. To me it would be as bad as if the
compiler implementation team redesigned arithmetic on the machine and used
different float layouts than the C compiler (or ABI) of the hardware vendor. On
special machines, yes you may have to. On machines with a proper operating
system, please don't bother!!

Greetings from London (warm and hazy).

Chris Morgan




^ permalink raw reply	[flat|nested] 17+ messages in thread
* Ada95 Streams Question
@ 1996-06-17  0:00 Chris.Morgan
  1996-06-18  0:00 ` Robert I. Eachus
  1996-06-19  0:00 ` Samuel Tardieu
  0 siblings, 2 replies; 17+ messages in thread
From: Chris.Morgan @ 1996-06-17  0:00 UTC (permalink / raw)



I have a question about Ada95 stream implementations. I mentioned this work a
little while back in response to a request for Ada95 success stories, but now
I'm feeling a little unsettled by accusations of being a hacker!

I'm principally aiming this at comp.lang.ada but cc:ing to report@gnat.com in
case someone there who's given up on the newsgroup cares to comment.

Background
==========

I have connected an Ada95 executable to a C++ executable using streams. The Ada
is the brains of the application, and the C++ is the Motif pretty face. On both
sides I have defined a set of portable types which application types are
converted to for transmission and converted from on receipt.

On the C++ side I have specialised the iostream operators in our C++ GUI
library for each low-level type (e.g. 1,2 and 4-byte signed integers, 4-byte
float, 8-byte float and so on) so that binary reads are performed, not ASCII.
This is simply a case of casting the object to a char* of the correct size
before doing the read or write (>> or <<).

On the Ada side I have declared types that correspond to these low-level types,
deriving portable integer types from Interfaces.Integer_n and unsigned integers
from Interfaces.Unsigned_n types. The only special thing I have done is the C++
library stil expects a linefeed after each object (it normally reads files) so
I add that on after calling the 'write attribute for each object
(character'write(ASCII.LF)).

This is all working fine and I get good performance with a named pipe created
in /tmp which is a form of shared memory. In fact I have quite a nice scheme
going where I have defined a root tagged type which defines the header for any
message to the C++, and then any real message is derived from the root. To
write any particular derived type is simply matter of calling
type'write(object) and away it goes. The only bit not tested yet is floats
which aren't very important in this app.

Question
========

How likely is it that the GNAT (or some other Ada95 compiler) implementation of
Ada stream_io would arbitrarily break this arrangement in future? I am told
that the in-stream representation is only recommended to conform to the
in-memory, but what are the actual chances of some implementation not following
this advice?

Am I really relying entirely on a pure coincidence that the C++ and the Ada95
definitions can work together, or is it in fact the only sensible scheme?

Some of my more senior colleagues think that Ada95 stream_io is broken for
Ada/C++ interworking, but the fact that it works exactly as I expected in my
setup is either a) pure coincidence or b) the result of Ada streams (at least
with GNAT) being implemented precisely to allow this. I know which I suspect!

Of course I am talking about the simple case where no tags are written (I'm not
using any dispatching) and no doping information, so I am suggesting that two
objects which are bitwise compatible in memory can naturally be passed forward
and back down streams between Ada95 and C++ and I can't see why this should
ever break.

(Note : I'm using GNAT3.05 on Sun-SPARC-Solaris2.5. Previous versions of GNAT
had a stream_io bug which held me up but which is now fixed. The C++ compiler
is the SunSoft SPARCCompilerC++ from SunSoft Visual Workshop for C++. Naturally
if the GUI worked with g++ I would have tried direct interworking.)

Thoughts?

Chris

--
--chris.morgan@baesema.co.uk
--Team Ada




^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~1996-07-02  0:00 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-06-23  0:00 Ada95 Streams Question Robert Dewar
1996-06-24  0:00 ` michael
1996-06-24  0:00   ` Laurent Pautet
1996-06-24  0:00   ` Robert Dewar
1996-06-28  0:00     ` Robert A Duff
1996-06-30  0:00       ` Robert Dewar
1996-06-28  0:00     ` michael
1996-06-28  0:00       ` Robert Dewar
1996-07-01  0:00         ` Laurent Pautet
1996-07-01  0:00           ` Robert Dewar
1996-07-02  0:00     ` sam
1996-06-25  0:00   ` Theodore E. Dennison
  -- strict thread matches above, loose matches on Subject: below --
1996-06-24  0:00 Chris.Morgan
1996-06-17  0:00 Chris.Morgan
1996-06-18  0:00 ` Robert I. Eachus
1996-06-19  0:00 ` Samuel Tardieu
1996-06-20  0:00   ` Robert Dewar

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