comp.lang.ada
 help / color / mirror / Atom feed
From: "Sébastien Morand" <seb.morand@gmail.com>
Subject: Re: Interfacing to C and long long data type
Date: Thu, 26 Jun 2008 08:53:29 +0000
Date: 2008-06-26T08:53:29+00:00	[thread overview]
Message-ID: <48635909.8060204@gmail.com> (raw)
In-Reply-To: <4abde3e1-3c8c-4b01-b63b-d29e7039070b@f36g2000hsa.googlegroups.com>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

> GNAT already defines Interfaces.Integer_64, so I guess I can use that
> as well. I was not sure if it would be fully legal to do so.
> Considering the fact that representation of integers in C is largely
> left to the implementation, any interoperability is achieved only with
> the assumption that the compiler does the right thing, but with GNAT
> and the C part compiled with gcc, this should be the case.

Anyway when you interface Ada with C, you are loosing the portability of
your program, because you are never sure of the size of any type since C
definition of type is quite imprecise. Of course standard type match
quite well (Int, Long in ada are in the same size of int and long in C)
but when you use Integer_64, this is not.

So you have to create a configure style program checking the size of you
data and using the right one.

This is espcially true when using C structure that you have to define by
yourself:

For instance :

struct my_struct {
   int field1,
   char* field2,
   long field3
};

with Interface.C; use Interfaces.C;

package Interface.My_Structures is

   type My_Struct is record
      Field1: Int;
      Field2: System.Address;
      Field3: Long;
   end record;

end Interface.My_Structures;

But if you get a new version of my_struct using a new field. You could
get core dumped or wrong behaviour :

struct my_struct {
   int field1,
   char* field2,
   unsigned int field2_length,
   long field3
};

So be careful.

S�bastien
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (Cygwin)

iD8DBQFIY1kJ+zV9xm4PlDQRAuYaAJ40/HEceKuwt2wLp0qOfc+qlBxnegCePNah
4ejBkkzVx/TmfEtzJ2Cc8mg=
=LE1d
-----END PGP SIGNATURE-----



  reply	other threads:[~2008-06-26  8:53 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-25 15:23 Interfacing to C and long long data type Maciej Sobczak
2008-06-25 16:55 ` Keith Thompson
2008-06-25 21:35   ` Maciej Sobczak
2008-06-26  8:53     ` Sébastien Morand [this message]
2008-06-26 10:19       ` Georg Bauhaus
2008-06-26 11:59       ` Maciej Sobczak
2008-06-27 14:31         ` Sébastien Morand
2008-06-27 16:11         ` Dmitry A. Kazakov
2008-06-27 18:53           ` Adam Beneschan
2008-06-27 20:29             ` Simon Wright
2008-06-27 20:46             ` Dmitry A. Kazakov
2008-06-25 19:08 ` Simon Wright
replies disabled

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