Frank Hofmann wrote: > Hi, > > I'm looking for a generic opinion on the use of "#pragma pack" for > writing Solaris code. I know it's useful for device register sets, or > data structures that don't follow ABI layout rules. > > We use #pragma pack(4) at a few places in Solaris (for example, the > SVM on-disk layout data structures on Solaris/x86). > > Should such a use be allowed or discouraged for new code ? I.e. if I > have a data structure that is packed (no padding, contains misaligned > multibyte entities), should I better write a convertor function or > were it ok to use #pragma pack(1) ? > > Thanks, > FrankH. > _______________________________________________ > opensolaris-code mailing list > [email protected] > http://mail.opensolaris.org/mailman/listinfo/opensolaris-code
I have mixed opinions about this. Personally, for most of the cases where you are interfacing with devices, I think the ddi accessor functions is best. However, for certain use cases -- like network protocols and on-disk formats, I think packing is completely reasonable. In those cases, be certain you use intXX_t, e.g. int32_t, uint16_t, etc. rather than relying on the size of native data types. Of course, I don't work for Sun, and I don't speak for Solaris. But its just my opinion. -- Garrett D'Amore, Principal Software Engineer Tadpole Computer / Computing Technologies Division, General Dynamics C4 Systems http://www.tadpolecomputer.com/ Phone: 951 325-2134 Fax: 951 325-2191 _______________________________________________ opensolaris-code mailing list [email protected] http://mail.opensolaris.org/mailman/listinfo/opensolaris-code
