Skip to content

Commit d2c470f

Browse files
j6tgitster
authored andcommitted
lazyload.h: fix warnings about mismatching function pointer types
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)) | ^~~~~~~~~~~~~~ (message wrapped 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. Helped-by: Carlo Marcelo Arenas Belón <carenas@gmail.com> Signed-off-by: Johannes Sixt <j6t@kdbg.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 99c99ed commit d2c470f

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

compat/win32/lazyload.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ struct proc_addr {
2626
#define DECLARE_PROC_ADDR(dll, rettype, function, ...) \
2727
static struct proc_addr proc_addr_##function = \
2828
{ #dll, #function, NULL, 0 }; \
29-
static rettype (WINAPI *function)(__VA_ARGS__)
29+
typedef rettype (WINAPI *proc_type_##function)(__VA_ARGS__); \
30+
static proc_type_##function function
3031

3132
/*
3233
* Loads a function from a DLL (once-only).
@@ -35,7 +36,7 @@ struct proc_addr {
3536
* This function is not thread-safe.
3637
*/
3738
#define INIT_PROC_ADDR(function) \
38-
(function = get_proc_addr(&proc_addr_##function))
39+
(function = (proc_type_##function)get_proc_addr(&proc_addr_##function))
3940

4041
static inline FARPROC get_proc_addr(struct proc_addr *proc)
4142
{

0 commit comments

Comments
 (0)