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

Consider testing __STDC_VERSION__ >= 202000L in avif.h for C compiler's [[nodiscard]] support #2352

Closed
wantehchang opened this issue Jul 31, 2024 · 2 comments

Comments

@wantehchang
Copy link
Collaborator

The [[nodiscard]] attribute will be added to C23. That's why we are testing __STDC_VERSION__ >= 202311L in avif.h.

Experiments showed that if we pass the -std=c2x or -std=gnu2x option to recent versions of GCC and Clang (including Apple Clang), the __STDC_VERSION__ macro is defined as 202000L. So we may want to change the __STDC_VERSION__ >= 202311L test to __STDC_VERSION__ >= 202000L in avif.h.

Note: If we pass the /std:clatest option to MSVC, __STDC_VERSION__ macro is defined as 202312L.

@wantehchang
Copy link
Collaborator Author

This test program prints the value of __STDC_VERSION__:

#include <stdio.h>

int main(void) {
  printf("__STDC_VERSION__ = %ldL\n", __STDC_VERSION__);
  return 0;
}

For GCC and Clang, we can use the command echo | gcc -std=c2x -dM -E - | grep __STDC_VERSION__ or echo | clang -std=c2x -dM -E - | grep __STDC_VERSION__.

wantehchang added a commit to wantehchang/libavif that referenced this issue Aug 1, 2024
wantehchang added a commit to wantehchang/libavif that referenced this issue Aug 1, 2024
wantehchang added a commit to wantehchang/libavif that referenced this issue Aug 1, 2024
wantehchang added a commit to wantehchang/libavif that referenced this issue Aug 1, 2024
@vrabaud
Copy link
Collaborator

vrabaud commented Aug 27, 2024

According to the standard, (cf https://open-std.org/JTC1/SC22/WG14/www/docs/n3220.pdf , look for the string 201904L), 201904L should do it (if compilers implement it strictly ... but I doubt it for non-final C versions), so 202000L is fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants