Re: gcc structures

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



How will you use this struct once you have it aligned the way you want?

If you use it as a tx/rx buffer, be aware that doubles aren't portable.
Let alone that ints could be different size on different machines.
Even if your just writing these structs to file. The resulting file will
not be portable across architectures.

//bar is packed; slower to access.
struct special_packed_machine_dependent_struct bar = ...;

//result is binary compatible only with similar machines.
write(fd, &bar, sizeof(bar));

If the task is small It may be better to fiddle the bits/bytes yourself.

uint8_t buff[HEADE_SIZE];

get_data_from_someplace(buff);

//bar is not aligned. therefore possibly faster to access.
struct special_machine_dependent_struct bar;

//construct MEMBER preserving byte order.
bar.member = (buff[U16_MEMBER_OFFSET+1]<<8)|(buff[U16_MEMBER_OFFSET]);

I don't know what GIS shapefiles are so... The above may be pure lunacy.

MS.





[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux