Re: Ada array vs C pointer (call by reference)



Maciej Sobczak <see.my.homepage@xxxxxxxxx> writes:
On 27 Cze, 04:55, Adam Beneschan <a...@xxxxxxxxxx> wrote:
Oh, and you probably want to use Interfaces.C.C_Float instead of the
Ada type "Float", to ensure that you're using the same kind of float
that the C routine expects.

Don't get me wrong, but I find it a bit of handwaving.
Ada *cannot* guarantee that Interfaces.C.C_Float is the *right* float,
because it does not verify how the C code was compiled and there is a
lot of freedom given to C implementers in this area.
Same for all other types.

No, Ada can't guarantee it directly. Instead, Ada requires the
implementation to guarantee it.

In reality we have to rely on some external knowledge about the
implementation - but then, Interfaces.C.XXX have little added value,
because we might as well have the same knowledge about types from
Standard.

Is there any implementation where Interfaces.C.int has different
properties than Integer?

I don't know, and I suggest that you don't know either.

To answer that question, you'd have to look at every existing Ada
implementation, and at every existing C implementation that targets
the same systems.

To answer it usefully, you'd also have to look at every *future*
implementation on which your code might run.

There is no fundamental reason to assume that Ada's Integer and C's
int have the same properties. That's exactly why Interfaces.C exists.

Look at it this way. You have the choice of using
Interfaces.C.C_Float, which (assuming the Ada implementation gets it
right), is guaranteed to match C's float, or of using Float, which has
no such guarantee (but saves a little typing). Why would you even
consider using Float?

--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
.



Relevant Pages

  • Re: Ada array vs C pointer (call by reference)
    ... I have a C library function which takes a float * as a parameter. ... where data is an array of float which size is determined by pwmCount. ... In Ada, I have: ... I've never heard of an Ada compiler that doesn't, ...
    (comp.lang.ada)
  • Re: Reading Float Data from a binary file into ada
    ... but store it into a 32 bit Float. ... Any reason you can't call this C function from Ada? ... a round about syntax to help me get started in setting up the memory ...
    (comp.lang.ada)
  • Re: Reading Float Data from a binary file into ada
    ... Essentially I was given a Visual Basic program that dumps a binary configuration file with all of the variables in a set. ... The variables are each 32 bit floats, with the first 16 bits being the integer part and the second 16 bits being a representation of the fraction (I'm not sure if this is stanard - but its just how VB dumps the data). ... There is a C counterpart to this that makes use of a 'union' to grab the data 1 byte at a time, put them into a char array of size 4, then use a 32 bit float to reference the data. ... Is there somehow I can do this in ada as well? ...
    (comp.lang.ada)
  • Re: urgent question - generics
    ... -- types of calls both Ada and non-Ada procedure. ... return float is ... pragma Import (Ada, tst); ... What I did for my first Ada assignment after modifying it, ...
    (comp.lang.ada)
  • Re: Reading Float Data from a binary file into ada
    ... but store it into a 32 bit Float. ... We are using simulink and calling ada through s-functions. ... a round about syntax to help me get started in setting up the memory ...
    (comp.lang.ada)

Loading