From: awdorrin <awdorrin@gmail.com>
Subject: Interfacing between Ada and C: records and structs
Date: Tue, 31 Jul 2012 09:38:51 -0700 (PDT)
Date: 2012-07-31T09:38:51-07:00 [thread overview]
Message-ID: <296e271a-967b-4dfb-8dca-f278ecfae03d@googlegroups.com> (raw)
I have some legacy code that I am working with, they share common data structures.
Simplifying my code, In Ada, I have a record:
type FP_SHARED_BUF_TYPE is
record
LOCK_SHM_1 : aliased Mutex;
LOCK_SHM_2 : aliased Mutex;
LOCK_SHM_3 : aliased Mutex;
end record;
pragma Convention(C,FP_SHARED_BUF_TYPE);
In C:
struct FP_SHARED_TYPE {
pthread_mutex_t LOCK_SHM_1;
pthread_mutex_t LOCK_SHM_2;
pthread_mutex_t LOCK_SHM_3;
};
Now, the Mutex/pthread_mutex_t is 192bits, not 255bits, but when I compile the program.
The Ada code defines the record as:
for FP_SHARED_BUF_TYPE'Alignment use 9;
for FP_SHARED_BUF_TYPE use record
LOCK_SHM_1 at - range 0 .. 255;
LOCK_SHM_1 at - range 32 .. 255;
LOCK_SHM_1 at - range 64 .. 255;
end record;
While the C code defines the structure elements as 192bits, and packs them right next to each other
Addresses of:
LOCK_SHM_1 0xF5650008
LOCK_SHM_2 0xF5650020
LOCK_SHM_3 0xF5650038
The only way I can get this to work, is to add padding to my C struct definition:
struct FP_SHARED_TYPE {
pthread_mutex_t LOCK_SHM_1;
int pad_for_m1[2];
pthread_mutex_t LOCK_SHM_2;
int pad_for_m2[2];
pthread_mutex_t LOCK_SHM_3;
int pad_for_m3[2];
};
Which, makes the C code really ugly.
Is there a way to make the Ada code pack the record?
I have been looking through the docs and haven't seen it yet.
next reply other threads:[~2012-08-07 6:10 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-31 16:38 awdorrin [this message]
2012-07-31 17:16 ` Interfacing between Ada and C: records and structs Niklas Holsti
2012-07-31 18:44 ` awdorrin
2012-07-31 19:08 ` awdorrin
2012-07-31 19:27 ` Simon Wright
2012-07-31 19:44 ` awdorrin
2012-07-31 20:46 ` Niklas Holsti
2012-08-01 12:16 ` awdorrin
2012-07-31 19:23 ` Simon Wright
2012-08-02 4:39 ` Shark8
2012-08-02 12:32 ` awdorrin
[not found] <7beb59ba-ca6f-476e-8b39-604196b0b79f@googlegroups.com>
2012-08-01 2:51 ` Jeffrey Carter
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox