From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,d8ff1403929a72c0,start X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.141.225 with SMTP id rr1mr519921pbb.2.1344319815352; Mon, 06 Aug 2012 23:10:15 -0700 (PDT) Path: p10ni2516515pbh.1!nntp.google.com!npeer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!border4.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!ctu-peer!ctu-gate!news.nctu.edu.tw!usenet.stanford.edu!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail From: awdorrin Newsgroups: comp.lang.ada Subject: Interfacing between Ada and C: records and structs Date: Tue, 31 Jul 2012 09:38:51 -0700 (PDT) Organization: http://groups.google.com Message-ID: <296e271a-967b-4dfb-8dca-f278ecfae03d@googlegroups.com> NNTP-Posting-Host: 192.35.35.34 Mime-Version: 1.0 X-Trace: posting.google.com 1343752732 5606 127.0.0.1 (31 Jul 2012 16:38:52 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 31 Jul 2012 16:38:52 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=192.35.35.34; posting-account=YkFdLgoAAADpWnfCBA6ZXMWTz2zHNd0j User-Agent: G2/1.0 X-Received-Bytes: 2485 Content-Type: text/plain; charset=ISO-8859-1 Date: 2012-07-31T09:38:51-07:00 List-Id: 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.