Skip to content

Commit ce60aa6

Browse files
committed
Work-around for -Wcast-function-type warning from GetProcAddress()
Apparently, the way to silence this warning is to cast the value returned by GetProcAddress() to a void function pointer, _then_ cast it to the type we actually want. Hat tipped to GPUOpen-Tools/volk@8219a21189 .
1 parent e9ddc8c commit ce60aa6

2 files changed

Lines changed: 18 additions & 6 deletions

File tree

wincon/pdcscrn.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ typedef struct _CONSOLE_SCREEN_BUFFER_INFOEX {
8989
typedef CONSOLE_SCREEN_BUFFER_INFOEX *PCONSOLE_SCREEN_BUFFER_INFOEX;
9090
#endif
9191

92-
typedef BOOL (WINAPI *SetConsoleScreenBufferInfoExFn) (HANDLE, CONSOLE_SCREEN_BUFFER_INFOEX *);
93-
typedef BOOL (WINAPI *GetConsoleScreenBufferInfoExFn) (HANDLE, CONSOLE_SCREEN_BUFFER_INFOEX *);
92+
typedef BOOL (WINAPI *SetConsoleScreenBufferInfoExFn) (_In_ HANDLE, _Out_ CONSOLE_SCREEN_BUFFER_INFOEX *);
93+
typedef BOOL (WINAPI *GetConsoleScreenBufferInfoExFn) (_In_ HANDLE, _Out_ CONSOLE_SCREEN_BUFFER_INFOEX *);
9494

9595
static SetConsoleScreenBufferInfoExFn pSetConsoleScreenBufferInfoEx = NULL;
9696
static GetConsoleScreenBufferInfoExFn pGetConsoleScreenBufferInfoEx = NULL;
@@ -376,6 +376,11 @@ void PDC_scr_free(void)
376376
SetConsoleCtrlHandler(_ctrl_break, FALSE);
377377
}
378378

379+
/* In casting function pointers, we first cast them through a void function pointer.
380+
This suppresses cast-function-type warnings on gcc and MinGW. */
381+
382+
#define VOID_FN_PTR (void(*)(void))
383+
379384
/* open the physical screen -- miscellaneous initialization, may save
380385
the existing screen for later restoration */
381386

@@ -479,10 +484,10 @@ int PDC_scr_open(void)
479484

480485
h_kernel = GetModuleHandleA("kernel32.dll");
481486
pGetConsoleScreenBufferInfoEx =
482-
(GetConsoleScreenBufferInfoExFn)GetProcAddress(h_kernel,
487+
(GetConsoleScreenBufferInfoExFn) VOID_FN_PTR GetProcAddress(h_kernel,
483488
"GetConsoleScreenBufferInfoEx");
484489
pSetConsoleScreenBufferInfoEx =
485-
(SetConsoleScreenBufferInfoExFn)GetProcAddress(h_kernel,
490+
(SetConsoleScreenBufferInfoExFn) VOID_FN_PTR GetProcAddress(h_kernel,
486491
"SetConsoleScreenBufferInfoEx");
487492

488493
return OK;

wingui/pdcscrn.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2080,6 +2080,11 @@ INLINE int set_up_window( void)
20802080
return( 0);
20812081
}
20822082

2083+
/* In casting function pointers, we first cast them through a void function pointer.
2084+
This suppresses cast-function-type warnings on gcc and MinGW. */
2085+
2086+
#define VOID_FN_PTR (void(*)(void))
2087+
20832088
/* open the physical screen -- allocate SP, miscellaneous intialization,
20842089
and may save the existing screen for later restoration.
20852090
@@ -2093,6 +2098,8 @@ INLINE int set_up_window( void)
20932098
#define MAX_LINES 50000
20942099
#define MAX_COLUMNS 50000
20952100

2101+
typedef HRESULT (*dpi_aware_func_t)(int);
2102+
20962103
int PDC_scr_open(void)
20972104
{
20982105
const HMODULE hntdll = GetModuleHandle( _T("ntdll.dll"));
@@ -2105,8 +2112,8 @@ int PDC_scr_open(void)
21052112

21062113
if ( shcoredll) {
21072114
static int ADJUST_DPI_PER_MONITOR = 2;
2108-
FARPROC set_process_dpi_awareness_func =
2109-
GetProcAddress(shcoredll, "SetProcessDpiAwareness");
2115+
dpi_aware_func_t set_process_dpi_awareness_func = (dpi_aware_func_t)
2116+
VOID_FN_PTR GetProcAddress(shcoredll, "SetProcessDpiAwareness");
21102117

21112118
if ( set_process_dpi_awareness_func) {
21122119
set_process_dpi_awareness_func(ADJUST_DPI_PER_MONITOR);

0 commit comments

Comments
 (0)