NIFTI-Imaging / nifti_clib

C libraries for NIFTI support
Other
33 stars 24 forks source link

Make opts const, allowing literal parameter. #179

Closed shangjiaxuan closed 10 months ago

shangjiaxuan commented 11 months ago

The following code currently fails compile because function parameter opts is declared as non-const, disallowing literal constants.

    nifti_image* img = NULL;
    znzFile file = nifti_image_open("image.nii", "rb", &img);
seanm commented 10 months ago

@shangjiaxuan this would be a change to public API and so needs to be done carefully. The maintainers are conservative about changing public API. It might be best to do an audit of where const is missing and batch all such changes together. Similar to https://github.com/NIFTI-Imaging/nifti_clib/pull/165

shangjiaxuan commented 10 months ago

@seanm after searchin through the source code, I believe this is the only function that needs const added. In fact the corresponding function in nifti1_io.h and nifti1_io.c is declared and implemented as const. The use of opts is for the fopen("file", "rb")'s "rb" mode parameter, and literal is expected on same code path.

seanm commented 10 months ago

@shangjiaxuan oh, indeed that is weird that it is const in nifti1_io.c but not in nifti2_io.c. I would have expected the opposite.

@hjmjohnson @afni-rickr given the above, I vote for merging this. What do you think?

afni-rickr commented 10 months ago

I do not see a compilation failure for that, so it presumably depends on build options. But this seems like a fine update. Thanks @shangjiaxuan.