HDFGroup / hdf4

Official HDF4 Library Repository
Other
12 stars 24 forks source link

incompatible-pointer-types-discards-qualifiers in mfhdf/libsrc/putget.c #623

Open schwehr opened 5 months ago

schwehr commented 5 months ago

This is with llvm from it's main branch about 2-3 weeks ago. From hdf4 at a6eec0d868e5935606be3cfd4332c025a6b1e9e5

I'm still seeing one compiler warning that is probably pretty easy to fix.

third_party/hdf4/mfhdf/libsrc/putget.c:1417:45: error: passing 'const void *' to parameter of type 'char *' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
 1417 |     return (NCvar1io(handle, varid, coords, value));
      |                                             ^~~~~
third_party/hdf4/mfhdf/libsrc/putget.c:1353:59: note: passing argument to parameter 'value' here
 1353 | NCvar1io(NC *handle, int varid, const long *coords, Void *value)
      | 
derobins commented 5 months ago

Unfortunately, this will require significant rework to fix.

NCvar1io() will pass the value pointer to hdf_xdr_NCv1data(), then hdf_xdr_NCvdata(). That function can perform both encode and decode operations on the passed-in void pointer, so at some point there is going to be a const warning. Personally, I'd rather have a write buffer flagged as const until we have to strip it out vs. remove const entirely to make the compiler happy.

In HDF5, we use compiler-specific warning suppression to quiet those architectural "kinda const" situations. We'll probably bring those over to HDF4 in the next release, but we should also rework the stripped-down XDR layer that remains to have explicit encode and decode calls, which would go a long way towards proper const usage.