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

Re: [PATCH cb/pedantic-build-for-developers] lazyload.h: fix warnings about mismatching function pointer types

From
Carlo Arenas <carenas@gmail.com>
Date
Sep 22, 2021, 20:16 UTC
Message-ID
<CAPUEspguHsx+BtViT5tO3eyZSJf7mJ0of-K3vAMqB0-ju4fpsg@mail.gmail.com>
In-Reply-To
<4381472f-a9db-b8a7-a395-81c3935309ae@kdbg.org>
On Wed, Sep 22, 2021 at 12:56 PM Johannes Sixt <j6t@kdbg.org> wrote:
Show 15 quoted lines
>
> Here, GCC warns about every use of the INIT_PROC_ADDR macro, for example:
>
> In file included from compat/mingw.c:8:
> compat/mingw.c: In function 'mingw_strftime':
> compat/win32/lazyload.h:38:12: warning: assignment to
>    'size_t (*)(char *, size_t,  const char *, const struct tm *)'
>    {aka 'long long unsigned int (*)(char *, long long unsigned int,
>       const char *, const struct tm *)'} from incompatible pointer type
>    'FARPROC' {aka 'long long int (*)()'} [-Wincompatible-pointer-types]
>    38 |  (function = get_proc_addr(&proc_addr_##function))
>       |            ^
> compat/mingw.c:1014:6: note: in expansion of macro 'INIT_PROC_ADDR'
>  1014 |  if (INIT_PROC_ADDR(strftime))
>       |      ^~~~~~~~~~~~~~
did you have CFLAGS adding -Wincompatible-pointer-types explicitly?

This is the reason why the code that got merged to master had -Wno for this case.

> (message wrapper for convenience). Insert a cast to keep the compiler
> happy. A cast is fine in these cases because they are generic function
> pointer values that have been looked up in a DLL.

I have a more complete "fix" which I got stuck testing GGG[1]; you are likely going to also hit -Wcast-function-type otherwise.

>
> Signed-off-by: Johannes Sixt <j6t@kdbg.org>
> ---
>  How can this have worked ever without a warning?

POSIX have a specific exception that allows (void *) for this, it is incorrect though in platforms where pointers to code and data might be different (ex DOS with its segmented model)

Carlo
[1] https://github.com/git/git/pull/1094
Previous: Johannes SixtNext: Johannes Sixt
Message 2 of 25 in “lazyload.h: fix warnings about mismatching function pointer types”
  1. lazyload.h: fix warnings about mismatching function pointer typesJohannes Sixt, Sep 22, 2021
  2. Carlo ArenasSep 22, 2021
  3. Johannes SixtSep 22, 2021
  4. Carlo ArenasSep 23, 2021
  5. lazyload.h: use an even more generic function pointer than FARPROCCarlo Marcelo Arenas Belón, Sep 23, 2021
  6. Johannes SixtSep 23, 2021
  7. Carlo ArenasSep 23, 2021
  8. lazyload.h: use an even more generic function pointer than FARPROCCarlo Marcelo Arenas Belón, Sep 23, 2021
  9. 0/2 js/win-lazyload-buildfixCarlo Marcelo Arenas Belón, Sep 26, 2021
  10. 1/2 lazyload.h: fix warnings about mismatching function pointer typesCarlo Marcelo Arenas Belón, Sep 26, 2021
  11. Eric SunshineSep 27, 2021
  12. 2/2 lazyload.h: use an even more generic function pointer than FARPROCCarlo Marcelo Arenas Belón, Sep 26, 2021
  13. Junio C HamanoSep 27, 2021
  14. Carlo ArenasSep 27, 2021
  15. Junio C HamanoSep 27, 2021
  16. 0/3 js/win-lazyload-buildfixCarlo Marcelo Arenas Belón, Sep 29, 2021
  17. 1/3 lazyload.h: fix warnings about mismatching function pointer typesCarlo Marcelo Arenas Belón, Sep 29, 2021
  18. 2/3 lazyload.h: use an even more generic function pointer than FARPROCCarlo Marcelo Arenas Belón, Sep 29, 2021
  19. 3/3 Makefile: restrict -Wpedantic and -Wno-pedantic-ms-format betterCarlo Marcelo Arenas Belón, Sep 29, 2021
  20. Ramsay JonesSep 29, 2021
  21. 0/3 js/win-lazyload-buildfixCarlo Marcelo Arenas Belón, Sep 29, 2021
  22. 1/3 lazyload.h: fix warnings about mismatching function pointer typesCarlo Marcelo Arenas Belón, Sep 29, 2021
  23. 2/3 lazyload.h: use an even more generic function pointer than FARPROCCarlo Marcelo Arenas Belón, Sep 29, 2021
  24. 3/3 Makefile: restrict -Wpedantic and -Wno-pedantic-ms-format betterCarlo Marcelo Arenas Belón, Sep 29, 2021
  25. Carlo ArenasSep 23, 2021

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.