On Fri, Jul 25, 2014 at 09:38:11PM +0200, Aurelien Jacobs wrote: > > You can't map raw data from the file to a struct like this for at least > 2 reasons: > - the compiler is free to add some alignment padding between the struct > fields which would prevent them to map to the data you expect > - the data stored in the file may not match the endianness of the host > trying to read it > > To solve this issue, you should use the RL16() and RL32() macro to read > directly from raw data. (you may need to add a RL64() version of the > macro)
Note you can use __attribute((packed))__ on the struct in GCC (and similar constructs in other compilers), to avoid the first problem. You will still need to use RL32() etc to wrap accesses to the values, but as long as you do then I don't see any other issues with using a struct for this. It makes for much nicer code than doing everything by hand with offsets. Martin ------------------------------------------------------------------------------ Want fast and easy access to all the code in your enterprise? Index and search up to 200,000 lines of code with a free copy of Black Duck Code Sight - the same software that powers the world's largest code search on Ohloh, the Black Duck Open Hub! Try it now. http://p.sf.net/sfu/bds _______________________________________________ sigrok-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/sigrok-devel

