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 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: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , 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/