bug-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Unable to cross build for Windows


From: Torbjorn SVENSSON
Subject: Re: Unable to cross build for Windows
Date: Fri, 9 Jun 2023 14:16:52 +0200
User-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0



On 2023-06-09 09:11, Eli Zaretskii wrote:
From: Martin Dorey <Martin.Dorey@hitachivantara.com>
CC: "bug-make@gnu.org" <bug-make@gnu.org>
Date: Fri, 9 Jun 2023 06:32:28 +0000
msip_labels:

#include <stdint.h>

intptr_t _get_osfhandle(int);
typedef void* HANDLE;

HANDLE fn() {
   return (HANDLE)_get_osfhandle(0);
}
martind@sirius:~/tmp/svensson-2023-06-08$ gcc -c -Wbad-function-cast make.c
make.c: In function ‘fn’:
make.c:7:10: warning: cast from function call of type ‘intptr_t {aka long int}’ 
to non-matching type ‘void *’ [-Wbad-function-cast]
    return (HANDLE)_get_osfhandle(0);
           ^
martind@sirius:~/tmp/svensson-2023-06-08$

That's gcc-6.3, but it's much the same in every version I tested from gcc-4.4 
to gcc-10.  A random version's man page, 
https://gcc.gnu.org/onlinedocs/gcc-9.1.0/gcc/Warning-Options.html, explains the 
flag as to:

Warn when a function call is cast to a non-matching type. For example, warn if 
a call to a function returning an integer type is cast to a pointer type.

I fear they mean exactly what they say there.  So, while you might call it a 
mistake, I don't think it's an accident.  
https://stackoverflow.com/a/35308713/18096 has some explanation of why it might 
sometimes be useful... and how it could be sidestepped by a change to Gnu Make, 
like our new friend wished for.

Yes, it sounds like -Wbad-function-cast will always emit a warning in
such cases, and one cannot use it with the likes of _get_osfhandle,
which _require_ such casts.

You can, of course, work around it; the following compiles without a
warning:

#include <stdint.h>

intptr_t _get_osfhandle(int);
typedef void* HANDLE;

HANDLE fn() {
   intptr_t handle = _get_osfhandle(0);
   return (HANDLE)handle;
}

Okay, lets go this way to fix the warning to allow building with 
-Wbad-function-cast.

The only thing left, that I don't know how to handle, is the use of O() where 
the 3rd parameter is not a string literal.

src/job.c: In function 'create_batch_file':
src/job.c:365:3: error: format not a string literal and no format arguments 
[-Werror=format-security]
   O (fatal, NILF, error_string);
   ^

is it okay to change this to: fatal (NILF, 0, error_string);
or is there a better way to get around this warning?





reply via email to

[Prev in Thread] Current Thread [Next in Thread]