Re: [netcdfgroup] Files with compound types ARE portable!

  • To: Ed Hartnett <ed@xxxxxxxxxxxxxxxx>
  • Subject: Re: [netcdfgroup] Files with compound types ARE portable!
  • From: Jeff Whitaker <jswhit@xxxxxxxxxxx>
  • Date: Wed, 27 May 2009 17:00:50 -0600
Ed Hartnett wrote:
Jeff Whitaker <jswhit@xxxxxxxxxxx> writes:

     int ncid, typeid, varid, dimid, retval;
     char name[NC_MAX_NAME + 1];
     int dimids[] = {0};

     struct s1
     {
       short i;
       long long j;
     /*};*/
     } __attribute__ ((__packed__));


Howdy Jeff!

Your trouble is in your use of __attribute__ ((__packed__)).

This changes the packing of C structs, and that will not work, because
HDF5 has already figured out how your C compiler packs structs, and if
you change it, the HDF5 layer will become very confused.

If you wish to change the packing of structs by your C compiler, you
must do so with CFLAGS, and you must use the same CFLAGS when building
HDF5, then you must also use the same CFLAGS when building netCDF, and
the same CFLAGS whenever you compile user programs with compound types.

Without the "__attribute__ ((__packed__)) " this example works just
fine. In fact, I have incorporated it into libsrc4/tst_compounds.c.

Thanks,

Ed

Ed: Following your suggestion, I forwarded my previous email to the support-netcdf list.

Concerning packing of structs, one of us is very confused about how HDF5 compound types work (and it's probably me). I thought that you could specify arbitrary offsets that do not necessarily correspond to the default alignment of your C compiler, and HDF5 would take care of everything when you read the data back in. Otherwise, how would you read a file created with HDF5 on a platform with a different default alignment than the one it was written on? Isn't the whole point of the HDF5 layer that you don't have worry about the default alignment of structs for the C compiler?

Please enlighten me.

-Jeff



--
Jeffrey S. Whitaker         Phone  : (303)497-6313
Meteorologist               FAX    : (303)497-6449
NOAA/OAR/PSD  R/PSD1        Email  : Jeffrey.S.Whitaker@xxxxxxxx
325 Broadway                Office : Skaggs Research Cntr 1D-113
Boulder, CO, USA 80303-3328 Web    : http://tinyurl.com/5telg



  • 2009 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdfgroup archives: