What is the alternative to using #pragma pack (push n) and #pragma pack (pop)

397 views Asked by At

I've been reading a lot of comments on the use of #pragma pack, nearly all negative. I understand what it does and I can see the negative effects it may have but is there an alternative? Most of the code I write is to read/write/manipulate GIS data. How can I read (say) a shapefile if I don't pack the struct? The same goes for most of the data files I read. I'm not talking about files I create but downloaded files. If I buy a shapefile set for a particular area/feature then it will follow the ESRI specifications and will have no padding. Therefore, to read the data, I have to make structs with byte alignment. I know how to do all this but I wondered if there was any other way? Shapefiles, in particular, have been around since the 90s and I am sure that they must have been used on many different architectures without causing segmentation faults etc. Obviously, I am careful to reset the pack at the end of the header file. As a secondary question, many years ago now, I was advised to put my structs that required packing into a single header file and put the #pragma pack at the beginning and #pragma pack (pop) right at the end as opposed to packing each individual struct. Is this the best way?

I have been successfully reading/writing byte aligned data files for years without problems but the clang compiler is now throwing up a warning: /xpfstructs.h:8: warning: Unterminated '#pragma pack (push, ...)' at end of file The last line before #endif is #pragma pack (pop)

0

There are 0 answers