comp.lang.ada
 help / color / mirror / Atom feed
* LRM on passing data *from* C
@ 1999-05-21  0:00 dennison
  1999-05-22  0:00 ` Robert Dewar
  1999-05-22  0:00 ` Dale Stanbrough
  0 siblings, 2 replies; 6+ messages in thread
From: dennison @ 1999-05-21  0:00 UTC (permalink / raw)


All of the implementation advice in LRM B.3 (63-75) refers to how data
is passed *to* C. I'm curious if this advice was also meant to apply to
how data is passed *from* C when a C function calls an Ada subprogram.

I'm in a situation where the a compiler may not have followed the
advice. But we are calling Ada from C, so technicly the advice is not
applicable...

--
T.E.D.


--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---




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

* Re: LRM on passing data *from* C
  1999-05-21  0:00 LRM on passing data *from* C dennison
  1999-05-22  0:00 ` Robert Dewar
@ 1999-05-22  0:00 ` Dale Stanbrough
  1999-05-22  0:00   ` Robert Dewar
  1 sibling, 1 reply; 6+ messages in thread
From: Dale Stanbrough @ 1999-05-22  0:00 UTC (permalink / raw)


dennison@telepath.com wrote:


" All of the implementation advice in LRM B.3 (63-75) refers to how data
  is passed *to* C. I'm curious if this advice was also meant to apply to
  how data is passed *from* C when a C function calls an Ada subprogram.
  
  I'm in a situation where the a compiler may not have followed the
  advice. But we are calling Ada from C, so technicly the advice is not
  applicable..."


The Ada language can't say anything about how C compilers should
operate. For this you have to look to the C language standard.

For your particular application you'll have to examine the C calling
sequence for your particular compiler, and fiddle about with the Ada
code to make it match.


Dale




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

* Re: LRM on passing data *from* C
  1999-05-22  0:00   ` Dale Stanbrough
@ 1999-05-22  0:00     ` Robert Dewar
  0 siblings, 0 replies; 6+ messages in thread
From: Robert Dewar @ 1999-05-22  0:00 UTC (permalink / raw)


In article <dale-2205991156210001@r1021c-20.ppp.cs.rmit.edu.au>,
  dale@cs.rmit.edu.au (Dale Stanbrough) wrote:
> Robert Dewar wrote:
>
> How could  this be? If "int" is implemented by compiler A as
> being 16 bits, and by compiler B as 32 bits, how can you have
> one simple interface?

This is an Ada83 style question :-)

In Ada 95, this problem is 100% solved. The Ada compiler MUST
be written to understand the conventions of the C compiler. If
there are multiple C compilers with different conventions (an
unusual situation, probably only found in the chaotic PC world)
then a vendor has two alternatives:

1. Support one of these compilers, and document which one

2. Support two or more with separate conventions, e.g.

    pragma Export (Borland_C, procname);

In fact, even in the PC World, things seem to have settled
down reasonably well, for example int is always 32 bits these
days on PC's, at least those PC systems in which Ada-95 is
likely to come into contact.


--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---




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

* Re: LRM on passing data *from* C
  1999-05-21  0:00 LRM on passing data *from* C dennison
@ 1999-05-22  0:00 ` Robert Dewar
  1999-05-22  0:00   ` Dale Stanbrough
  1999-05-22  0:00 ` Dale Stanbrough
  1 sibling, 1 reply; 6+ messages in thread
From: Robert Dewar @ 1999-05-22  0:00 UTC (permalink / raw)


In article <7i4d5n$aaf$1@nnrp1.deja.com>,
  dennison@telepath.com wrote:
> All of the implementation advice in LRM B.3 (63-75) refers to
how data
> is passed *to* C. I'm curious if this advice was also meant to
apply to
> how data is passed *from* C when a C function calls an Ada
subprogram.
>
> I'm in a situation where the a compiler may not have followed
the
> advice. But we are calling Ada from C, so technicly the advice
is not
> applicable...


An Ada program exported with convention C is supposed to have
exactly the same calling sequence as a C program. The RM does
indeed define what this means.

However, this is only advice, so there is no reason to worry
too much about whether it applies or not. The advice is only
that, to be followed if it makes sense, to be ignored if it
does not.

I find it hard to justify a difference here, and would agree
it sounds like a bug, but there could be a reason (I just can't
think of one!)


--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---




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

* Re: LRM on passing data *from* C
  1999-05-22  0:00 ` Dale Stanbrough
@ 1999-05-22  0:00   ` Robert Dewar
  0 siblings, 0 replies; 6+ messages in thread
From: Robert Dewar @ 1999-05-22  0:00 UTC (permalink / raw)


In article <dale-2205990843320001@r1021c-20.ppp.cs.rmit.edu.au>,
  dale@cs.rmit.edu.au (Dale Stanbrough) wrote:
> The Ada language can't say anything about how C compilers
> should operate. For this you have to look to the C language
> standard.

That's misleading. The Ada standard *does* say that if you
export an Ada procedure with convention C, then it must have
a calling sequence compatible with C (it is up to the
implementor to ensure this)

> For your particular application you'll have to examine the C
> calling sequence for your particular compiler, and fiddle
> about with the Ada

This absolutely shoudl NOT be necessary in a well written
Ada 95 compiler.
> code to make it match.
>
> Dale
>


--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---




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

* Re: LRM on passing data *from* C
  1999-05-22  0:00 ` Robert Dewar
@ 1999-05-22  0:00   ` Dale Stanbrough
  1999-05-22  0:00     ` Robert Dewar
  0 siblings, 1 reply; 6+ messages in thread
From: Dale Stanbrough @ 1999-05-22  0:00 UTC (permalink / raw)


Robert Dewar wrote:

" An Ada program exported with convention C is supposed to have
  exactly the same calling sequence as a C program. The RM does
  indeed define what this means."


How could  this be? If "int" is implemented by compiler A as
being 16 bits, and by compiler B as 32 bits, how can you have
one simple interface?

Older compilers for the PC platform could easily have created 
legacy code in which in the calling conventions are based on
earlier processors (integer was 16 bits for the Meridian Ada 
compiler), while newer compilers produce 32 bit integers.

Dale




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

end of thread, other threads:[~1999-05-22  0:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-05-21  0:00 LRM on passing data *from* C dennison
1999-05-22  0:00 ` Robert Dewar
1999-05-22  0:00   ` Dale Stanbrough
1999-05-22  0:00     ` Robert Dewar
1999-05-22  0:00 ` Dale Stanbrough
1999-05-22  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