git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v3 2/2] compat/posix.h: simplify GIT_GNUC_PREREQ() comparison

From
Patrick Steinhardt <ps@pks.im>
Date
Jun 12, 2026, 13:27 UTC
Message-ID
<aiwJSBfRbUFZ70gP@pks.im>
In-Reply-To
<20260608124419.38905-2-dominik.loidolt@univie.ac.at>
On Mon, Jun 08, 2026 at 02:44:19PM +0200, Dominik Loidolt wrote:
> Replace the glibc-style bit-shift version comparison with an explicit
> major/minor comparison. This is easier to read and is consistent with
> the format already used by GIT_CLANG_PREREQ() and many BSD

It's a bit funny to use `GIT_CLANG_PREREQ()` as an argument here as we've just added it in the preceding commit.

Show 5 quoted lines
> <sys/cdefs.h> headers.
> 
> This has no runtime impact, as the macro is evaluated at compile time.
> It is also more future-proof, as it no longer assumes that GCC version
> components stay below 65536.

I feel like all the message needs to say is "let's do it for consistency, and it's easier to read". That would've been sufficient, whereas this argument here feels a bit thin.

Doesn't matter much though, and I think ultimately the message is fine as-is, even though the reasoning is a bit funny.

Show 25 quoted lines
> diff --git a/compat/posix.h b/compat/posix.h
> index ffdfd91c7b..deefc43f28 100644
> --- a/compat/posix.h
> +++ b/compat/posix.h
> @@ -4,22 +4,24 @@
>  #define _FILE_OFFSET_BITS 64
>  
>  /*
> - * Derived from Linux "Features Test Macro" header
> - * Convenience macros to test the versions of gcc (or
> - * a compatible compiler).
> + * Convenience macros to test the versions of GCC (or a compatible compiler).
>   * Use them like this:
>   *  #if GIT_GNUC_PREREQ (2,8)
> - *   ... code requiring gcc 2.8 or later ...
> + *   ... code requiring GCC 2.8 or later ...
>   *  #endif
>   *
> + * Note that Clang and other compilers define __GNUC__ for compatibility; use
> + * GIT_CLANG_PREREQ() to check for specific Clang versions.
> + *
>   * This macro of course is not part of POSIX, but we need it for the UNUSED
>   * macro which is used by some of our POSIX compatibility wrappers.
> -*/
> + */

It would've been nice to either move these changes into a preparatory commit or at least mention them

Show 9 quoted lines
>  #if defined(__GNUC__) && defined(__GNUC_MINOR__)
>  # define GIT_GNUC_PREREQ(maj, min) \
> -	((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
> +	((__GNUC__ > (maj)) || \
> +	 (__GNUC__ == (maj) && __GNUC_MINOR__ >= (min)))
>  #else
> - #define GIT_GNUC_PREREQ(maj, min) 0
> +# define GIT_GNUC_PREREQ(maj, min) 0
>  #endif
The change itself makes sense to me.

I'm not sure myself whether this could use another reroll. It's all just nits, and the intent is clear enough.

Thanks!
Patrick
Previous: Dominik LoidoltNext: Dominik Loidolt
Message 13 of 20 in “compat/posix.h: enable UNUSED warning messages for Clang”
  1. compat/posix.h: enable UNUSED warning messages for ClangDominik Loidolt, May 3, 2026
  2. Junio C HamanoMay 4, 2026
  3. Junio C HamanoMay 4, 2026
  4. Dominik LoidoltJun 5, 2026
  5. compat/posix.h: enable UNUSED warning messages for ClangDominik Loidolt, Jun 5, 2026
  6. Patrick SteinhardtJun 5, 2026
  7. Dominik LoidoltJun 5, 2026
  8. Patrick SteinhardtJun 5, 2026
  9. Dominik LoidoltJun 5, 2026
  10. Patrick SteinhardtJun 8, 2026
  11. 1/2 compat/posix.h: enable UNUSED warning messages for ClangDominik Loidolt, Jun 8, 2026
  12. 2/2 compat/posix.h: simplify GIT_GNUC_PREREQ() comparisonDominik Loidolt, Jun 8, 2026
  13. Patrick SteinhardtJun 12, 2026
  14. Dominik LoidoltJun 12, 2026
  15. 0/3 compat/posix.h: enable UNUSED warning messages for ClangDominik Loidolt, Jun 13, 2026
  16. 2/3 compat/posix.h: clean up GIT_GNUC_PREREQ() and UNUSEDDominik Loidolt, Jun 13, 2026
  17. 1/3 compat/posix.h: enable UNUSED warning messages for ClangDominik Loidolt, Jun 13, 2026
  18. 3/3 compat/posix.h: simplify GIT_GNUC_PREREQ() comparisonDominik Loidolt, Jun 13, 2026
  19. Junio C HamanoJun 13, 2026
  20. Patrick SteinhardtJun 15, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.