This is the mail archive of the cygwin mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Problems when moving Ubuntu -> Cygwin

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.


Unsubscribe info:
Problem reports:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]