[Gdal-dev] Structure member alignment suggestion

Frank Warmerdam warmerdam at pobox.com
Mon Jan 30 12:44:40 EST 2006


On 1/27/06, Ray Gardener <rayg at daylongraphics.com> wrote:
> FWIW, I came across a runtime problem when a project uses a different
> structure member alignment (e.g., 4 bytes) than whatever was used to
> build GDAL with (normally 8 bytes in MSVC/Pentium). For example, the
> OGRSpatialReference class will become misinterpreted. Below are the
> current and suggested member layouts:
>
> class CPL_DLL OGRSpatialReference
> {
>      int         nRefCount;
>      OGR_SRSNode *poRoot;
>      int         bNormInfoSet;
>      double      dfFromGreenwich;
>      double      dfToMeter;
>      double      dfToDegrees;
>      ...
> };
>
>
> Suggested:
>      double      dfFromGreenwich;
>      double      dfToMeter;
>      double      dfToDegrees;
>      OGR_SRSNode *poRoot;
>      int         nRefCount;
>      int         bNormInfoSet;

Ray,

I have made the suggested change in ogr_spatialref.h
(warning ... ABI change!) but I think that depending on this
or pragmas to ensure compatible structure packing is
problematic at best so this isn't something I am going to
pursue religiously in all include files.

Ultimately, you are safer accessing things through the C
API if portability and "mixability" of environments is very
important to you.

Best regards,
--
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | Geospatial Programmer for Rent




More information about the Gdal-dev mailing list