Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib/raster3d: fix -Wdeprecated-non-prototype compiler warnings #2901

Merged
merged 1 commit into from
Feb 17, 2024

Conversation

nilason
Copy link
Contributor

@nilason nilason commented Mar 21, 2023

Split read and write functions, using function pointers do not work as the parameters has deviating qualifiers (const vs non-const).

This is a, perhaps preferable, alternative to #2891.

It does introduce some repetitive code, but do not remove the correctly used const qualifiers in the Rast3d_key_set_double() and similar functions.

Note: the "write" part of Rast3d_readWriteWindow() in windowio.c is never used and therefore removed. A write function is easily implemented if needed.

@nilason nilason added enhancement New feature or request C Related code is in C labels Mar 21, 2023
@nilason nilason added this to the 8.4.0 milestone Mar 21, 2023
@nilason nilason force-pushed the fix_more_Wdeprecated-non-prototype_v2 branch from ae0ed52 to c308c96 Compare November 22, 2023 12:26
Split read and write functions, using function pointers do not work as the parameters
has deviating qualifiers (const vs non-const).
@nilason nilason force-pushed the fix_more_Wdeprecated-non-prototype_v2 branch from c308c96 to 76bc4d1 Compare February 15, 2024 10:12
@nilason nilason self-assigned this Feb 15, 2024
@nilason
Copy link
Contributor Author

nilason commented Feb 15, 2024

I would welcome review on this one. This PR together with #3344 are the last fixes to prepare GRASS code to work with and comply to C23 standard.

@echoix
Copy link
Member

echoix commented Feb 15, 2024

I've read about this C prototype discussion when Clang implemented it, and I'm favorable for it. From your changes, I could find one that I fully understood (the one that added a void instead of nothing in the prototype). I understand that it could only be breaking for users that would use our software as a library, and would have been using it potentially inappropriately. Including in 8.4 is appropriate then. I also understand the better warnings that the compiler can emit, so it's a bigger win.

As for the other lines, I'm not sure I understand the consequences of it, so I'm not sure how to review it confidently.

@nilason
Copy link
Contributor Author

nilason commented Feb 15, 2024

I've read about this C prototype discussion when Clang implemented it, and I'm favorable for it. From your changes, I could find one that I fully understood (the one that added a void instead of nothing in the prototype). I understand that it could only be breaking for users that would use our software as a library, and would have been using it potentially inappropriately. Including in 8.4 is appropriate then. I also understand the better warnings that the compiler can emit, so it's a bigger win.

It is not a Clang-thing, but a C23 standard feature (for background see eg. https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2841.htm). It is a step to modernise the code, enable it to build with C23+ compilers. We now require C11 conformance, but that may change, and this PR doesn't break anything for C11.

The more immediate cause for this PR is better described in #2891.

These are the compiler warnings issued:

header.c:45:21: warning: a function declaration without a prototype is deprecated in all versions of C [-Wstrict-prototypes]
    int (*headerInt)(), (*headerDouble)(), (*headerValue)();
                    ^
                     void
header.c:45:40: warning: a function declaration without a prototype is deprecated in all versions of C [-Wstrict-prototypes]
    int (*headerInt)(), (*headerDouble)(), (*headerValue)();
                                       ^
                                        void
header.c:45:58: warning: a function declaration without a prototype is deprecated in all versions of C [-Wstrict-prototypes]
    int (*headerInt)(), (*headerDouble)(), (*headerValue)();
                                                         ^
                                                          void
header.c:46:24: warning: a function declaration without a prototype is deprecated in all versions of C [-Wstrict-prototypes]
    int (*headerString)();
                       ^
                        void
header.c:62:27: warning: passing arguments to a function without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
    returnVal &= headerInt(headerKeys, RASTER3D_REGION_PROJ, proj);
                          ^
header.c:63:27: warning: passing arguments to a function without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
    returnVal &= headerInt(headerKeys, RASTER3D_REGION_ZONE, zone);
                          ^
header.c:65:30: warning: passing arguments to a function without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
    returnVal &= headerDouble(headerKeys, RASTER3D_REGION_NORTH, north);
                             ^
header.c:66:30: warning: passing arguments to a function without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
    returnVal &= headerDouble(headerKeys, RASTER3D_REGION_SOUTH, south);
                             ^
header.c:67:30: warning: passing arguments to a function without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
    returnVal &= headerDouble(headerKeys, RASTER3D_REGION_EAST, east);
                             ^
header.c:68:30: warning: passing arguments to a function without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
    returnVal &= headerDouble(headerKeys, RASTER3D_REGION_WEST, west);
                             ^
header.c:69:30: warning: passing arguments to a function without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
    returnVal &= headerDouble(headerKeys, RASTER3D_REGION_TOP, top);
                             ^
header.c:70:30: warning: passing arguments to a function without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
    returnVal &= headerDouble(headerKeys, RASTER3D_REGION_BOTTOM, bottom);
                             ^
header.c:72:27: warning: passing arguments to a function without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
    returnVal &= headerInt(headerKeys, RASTER3D_REGION_ROWS, rows);
                          ^
header.c:73:27: warning: passing arguments to a function without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
    returnVal &= headerInt(headerKeys, RASTER3D_REGION_COLS, cols);
                          ^
header.c:74:27: warning: passing arguments to a function without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
    returnVal &= headerInt(headerKeys, RASTER3D_REGION_DEPTHS, depths);
                          ^
header.c:76:30: warning: passing arguments to a function without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
    returnVal &= headerDouble(headerKeys, RASTER3D_REGION_NSRES, ns_res);
                             ^
header.c:77:30: warning: passing arguments to a function without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
    returnVal &= headerDouble(headerKeys, RASTER3D_REGION_EWRES, ew_res);
                             ^
header.c:78:30: warning: passing arguments to a function without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
    returnVal &= headerDouble(headerKeys, RASTER3D_REGION_TBRES, tb_res);
                             ^
header.c:80:27: warning: passing arguments to a function without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
    returnVal &= headerInt(headerKeys, RASTER3D_HEADER_TILEX, tileX);
                          ^
header.c:81:27: warning: passing arguments to a function without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
    returnVal &= headerInt(headerKeys, RASTER3D_HEADER_TILEY, tileY);
                          ^
header.c:82:27: warning: passing arguments to a function without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
    returnVal &= headerInt(headerKeys, RASTER3D_HEADER_TILEZ, tileZ);
                          ^
header.c:84:29: warning: passing arguments to a function without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
    returnVal &= headerValue(headerKeys, RASTER3D_HEADER_TYPE, "double",
                            ^
header.c:86:29: warning: passing arguments to a function without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
    returnVal &= headerValue(headerKeys, RASTER3D_HEADER_COMPRESSION, "0", "1",
                            ^
header.c:89:20: warning: passing arguments to a function without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
        headerValue(headerKeys, RASTER3D_HEADER_USERLE, "0", "1", 0, 1, useRle);
                   ^
header.c:91:20: warning: passing arguments to a function without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
        headerValue(headerKeys, RASTER3D_HEADER_USELZW, "0", "1", 0, 1, useLzw);
                   ^
header.c:93:27: warning: passing arguments to a function without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
    returnVal &= headerInt(headerKeys, RASTER3D_HEADER_PRECISION, precision);
                          ^
header.c:94:27: warning: passing arguments to a function without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
    returnVal &= headerInt(headerKeys, RASTER3D_HEADER_DATA_OFFSET, dataOffset);
                          ^
header.c:97:20: warning: passing arguments to a function without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
        headerValue(headerKeys, RASTER3D_HEADER_USEXDR, "0", "1", 0, 1, useXdr);
                   ^
header.c:98:29: warning: passing arguments to a function without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
    returnVal &= headerValue(headerKeys, RASTER3D_HEADER_HASINDEX, "0", "1", 0,
                            ^
header.c:100:30: warning: passing arguments to a function without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
    returnVal &= headerString(headerKeys, RASTER3D_HEADER_UNIT, unit);
                             ^
header.c:102:19: warning: passing arguments to a function without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
    if (!headerInt(headerKeys, RASTER3D_HEADER_VERTICAL_UNIT, vertical_unit))
                  ^
header.c:108:19: warning: passing arguments to a function without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
    if (!headerInt(headerKeys, RASTER3D_HEADER_VERSION, version)) {
                  ^

As for the other lines, I'm not sure I understand the consequences of it, so I'm not sure how to review it confidently.

If you don't feel comfortable with reviewing it, I won't blame you for not to :-). But studying the "old" code is quite educational. Pretty clever use of function pointers.

@lbartoletti
Copy link
Contributor

I'm ok with the change, and I tested with clang 14 on FreeBSD 14, and it's OK.

@nilason
Copy link
Contributor Author

nilason commented Feb 15, 2024

I'm ok with the change, and I tested with clang 14 on FreeBSD 14, and it's OK.

@lbartoletti Thanks!

Copy link
Member

@wenzeslaus wenzeslaus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was confused for a minute whether there is some new function prototype thing, but the sentence from the linked document clarified it for me:

Submission Date: 2021-10-10
...
Function declarators without prototypes have been an obsolescent feature since the very first ISO C standard. 33 years of advance warning should be enough.

:-)))

@nilason nilason merged commit 37c2bae into OSGeo:main Feb 17, 2024
25 checks passed
@nilason nilason deleted the fix_more_Wdeprecated-non-prototype_v2 branch February 17, 2024 20:03
@lbartoletti
Copy link
Contributor

Function declarators without prototypes have been an obsolescent feature since the very first ISO C standard. 33 years of advance warning should be enough.

And FYI, gcc14 will raise error on old C code: https://gcc.gnu.org/gcc-14/porting_to.html#c

jadenabrams100 pushed a commit to ncsu-csc472-spring2024/grass-CI-playground that referenced this pull request Feb 21, 2024
…#2901)

Split read and write functions, using function pointers do not work as the parameters
has deviating qualifiers (const vs non-const).
It does introduce some repetitive code, but do not remove the correctly used const
qualifiers in the Rast3d_key_set_double() and similar functions.
Note: the "write" part of Rast3d_readWriteWindow() in windowio.c is never used and
therefore removed. A write function is easily implemented if needed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C Related code is in C enhancement New feature or request libraries raster3d
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants