www.delorie.com/archives/browse.cgi | search |
X-Recipient: | archive-cygwin AT delorie DOT com |
X-SWARE-Spam-Status: | No, hits=-2.1 required=5.0 tests=AWL,BAYES_00,J_CHICKENPOX_66,SPF_PASS |
X-Spam-Check-By: | sourceware.org |
Message-ID: | <49CBB625.8020500@gmail.com> |
Date: | Thu, 26 Mar 2009 17:06:45 +0000 |
From: | Dave Korn <dave DOT korn DOT cygwin AT googlemail DOT com> |
User-Agent: | Thunderbird 2.0.0.17 (Windows/20080914) |
MIME-Version: | 1.0 |
To: | cygwin AT cygwin DOT com |
Subject: | Re: Problems when moving Ubuntu -> Cygwin |
References: | <fac6c19a0903260006g51fed1efmbe23dd15e6241fa2 AT mail DOT gmail DOT com> <fac6c19a0903260235t7d1fb85dsb3e11d194701bfd8 AT mail DOT gmail DOT com> |
In-Reply-To: | <fac6c19a0903260235t7d1fb85dsb3e11d194701bfd8@mail.gmail.com> |
Mailing-List: | contact cygwin-help AT cygwin DOT com; run by ezmlm |
List-Id: | <cygwin.cygwin.com> |
List-Subscribe: | <mailto:cygwin-subscribe AT cygwin DOT com> |
List-Archive: | <http://sourceware.org/ml/cygwin/> |
List-Post: | <mailto:cygwin AT cygwin DOT com> |
List-Help: | <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs> |
Sender: | cygwin-owner AT cygwin DOT com |
Mail-Followup-To: | cygwin AT cygwin DOT com |
Delivered-To: | mailing list cygwin AT cygwin DOT com |
Mikael Normark wrote: > I checked the size of int and long long on both systems and found that > they were the same but when I checked sizeof(struct sample_pkt_t) it > returned 396 on Ubuntu and 528 on Cygwin so I need to find a > workaround for the adressing issue, perhaps that solves the problem. It's a well-known problem in C that the same struct can be laid out differently on different machines according to padding rules. There is a lot of knowledge out there on the ways to address these problems when transferring data over a network, protocols like RPC use a process called "marshalling" to communicate data structures item-by-item in a canonical format, but that's perhaps a little over-engineered for your needs here. (Well, depends; are you planning on making this application part of a massive public deployment somewhere, or is it mostly for your own personal use?) >> // Holdning the raw sample data and timestamp when >> // the sample was fetched. >> struct sample_t{ >> int sample; >> long long timestamp; >> }; >> >> // A package that will hold samples data over >> // the TCP transfer. >> struct sample_pkg_t{ >> unsigned int type; //Should always be PKG_SAMPLES >> unsigned int pkg_nr; //Counter increased for each package >> unsigned int nr_samples; // Shouldbe same as ADC_SAMPLES_IN_PKG >> struct sample_t sample[SAMPLES_IN_PKG]; // The samples data >> }; If you want a quick bodge that will work for your situation (but it only works because Cygwin and Ubuntu have the same size types involved, and might well fall down when 64-bit hosts try to talk to 32-bit hosts), take a look in the GCC manual for the use of "attribute ((__packed__))" on the struct definition. You could make it more 32-vs-64 robust by replacing all the types with the stdint.h size-specific types (int -> int32_t, long long -> int64_t, unsigned int -> uint32_t) as well if you liked. cheers, DaveK -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/
webmaster | delorie software privacy |
Copyright © 2019 by DJ Delorie | Updated Jul 2019 |