comp.lang.ada
 help / color / mirror / Atom feed
From: emery@goldfinger.mitre.org (David Emery)
Subject: Re: C-Ada Import of struct's -- Help
Date: 18 Oct 94 09:58:16
Date: 1994-10-18T09:58:16+00:00	[thread overview]
Message-ID: <EMERY.94Oct18095816@goldfinger.mitre.org> (raw)
In-Reply-To: Bob Wells #402's message of Tue, 18 Oct 1994 11:20:30 +0100

I'm sorry, but Bob Wells' techniques are not very reliable/portable,
and will fail on many Ada compilers.

Bob makes the significant mistake of assuming that an Ada access type
has any relation to an address.  This is not a valid assumption on
some Ada compilers.  

Even when an access type is an address, it doesn't necessarily point
to the right thing.  By Definition in C, a "char *" representing a string
is the address of the first element of the string.  There's no
guarantee that an Ada access type points to the first element of the
string.  In fact, there is significant existing practice where the
access type points to a 'descriptor', which contains the address of
the first element of the string.  

The same reasoning holds true, even more so, for the other array type.  

Also, don't forget that a C string must be null-terminated.  Ada
provides no such guarantee for its strings.

In my (long and painful) experience interfacing Ada and C, I've found
that the right approach is to bend over backwards and provide C with 
the exact thing it asks for (e.g. the address of the first element of
a string is represented in Ada by STR(STR'FIRST)'ADDRESS).
Fortunately, we can use the features of Ada to hide this ugliness
within a package body, protecting the innocence of the programmer
using the package...

				dave
--
--The preceeding opinions do not necessarily reflect the opinions of
--The MITRE Corporation or its sponsors. 
-- "A good plan violently executed -NOW- is better than a perfect plan
--  next week"                                      George Patton
-- "Any damn fool can write a plan.  It's the execution that gets you
--  all screwed up"                              James Hollingsworth
-------------------------------------------------------------------------



  reply	other threads:[~1994-10-18  9:58 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1994-10-18 10:20 C-Ada Import of struct's -- Help Bob Wells #402
1994-10-18  9:58 ` David Emery [this message]
1994-10-18 19:11   ` Robert Dewar
1994-10-19 10:02     ` David Emery
1994-10-20  0:36     ` Keith Thompson @pulsar
  -- strict thread matches above, loose matches on Subject: below --
1994-10-19 13:57 Bob Wells #402
1994-10-18  3:34 mcnett michael david
1994-10-18  9:48 ` David Emery
replies disabled

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