Unidata / netcdf-c

Official GitHub repository for netCDF-C libraries and utilities.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Type of internal struct member causes lots of sign conversion warnings

ZedThree opened this issue · comments

In current main, there is a struct which is used as a header for many other objects:

typedef struct NC_OBJ
{
    NC_SORT sort; /**< Type of object. */
    char* name;   /**< Name, assumed to be null terminated. */
    size_t id;    /**< This objects ID. */
} NC_OBJ;

Here, id is a size_t, but in many places it's used or passed to an int. In fact, a quick grep shows it's used in ~240 places and it generates ~120 warnings. Switching it to an int only generates 5 warnings.

I think it's mostly used to store and look up various object IDs which are almost always int (at least in the public API), so perhaps that makes more sense?

I think this is a reasonable change. I will put up a PR for it.

There's quite a few other internal structs with similar issues. Would it make sense to move to try and consistently use int instead of size_t everywhere? There would still be issues at boundaries with other libraries (like HDF5 and the C stdlib), but they could be handled with casts as appropriate.

Replacing size_t with int across the board isn't going to work, unfortunately; even reviewing something like that would be difficult, there could be a lot of unintended consequences. Doing this on a case by case basis will be the best approach.