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=1.7 required=5.0 tests=BAYES_00,DATE_IN_PAST_24_48, FORGED_MUA_MOZILLA autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,d8ff1403929a72c0 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.236.136.202 with SMTP id w50mr12459635yhi.47.1343909969815; Thu, 02 Aug 2012 05:19:29 -0700 (PDT) Path: a15ni4867845qag.0!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!goblin3!goblin.stu.neva.ru!news.matabio.net!jeffrey.matabio.net!thue.elzevir.fr!news.davenulle.org!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Niklas Holsti Newsgroups: comp.lang.ada Subject: Re: Interfacing between Ada and C: records and structs Date: Tue, 31 Jul 2012 20:16:10 +0300 Organization: Tidorum Ltd Message-ID: References: <296e271a-967b-4dfb-8dca-f278ecfae03d@googlegroups.com> Mime-Version: 1.0 X-Trace: individual.net 1E8LyGJWdRf7lv1pXoe9QgsUtRm49PF6RvcCeEyT4VA00VXJIRK8fmJy/iZtEeOHFE Cancel-Lock: sha1:+55CblwKjpn5oAV+SmN3i2TSj3Y= User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:14.0) Gecko/20120713 Thunderbird/14.0 In-Reply-To: <296e271a-967b-4dfb-8dca-f278ecfae03d@googlegroups.com> X-Received-Bytes: 3349 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Date: 2012-07-31T20:16:10+03:00 List-Id: On 12-07-31 19:38 , awdorrin wrote: > 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. How is pthread_mutex_t declared in Ada form? And in C form? Have you checked that in Ada, pthread_mutex_t'Size is 192? What is the storage unit of your target processor? 8 bits? > The Ada code defines the record as: > > for FP_SHARED_BUF_TYPE'Alignment use 9; That is a strange alignment. Do you see any need for it? If not, try removing it. > 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; Do you see any need for this representation clause? If not, remove it. Or change it to use 192 bits per component. (What are the "-" characters after the "at" keywords? Shouldn't it read "at 0 range"?) > 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? If your Ada code includes the record representation clause quoted above, just remove it, or change it to specify 192 bits per component. -- Niklas Holsti Tidorum Ltd niklas holsti tidorum fi . @ .