Yes, depending on the target (32-bit or 64-bit), the INT_PTR will represent a different underlying type (think `int` vs `long long`) so the casting will be done accordingly.
Here also a link to the Microsoft's documentation: The New Data Types - Win32 apps | Microsoft Docs <https://docs.microsoft.com/en-us/windows/win32/winprog64/the-new-data-types#pointer-precision> Kind regards, Sergey On Thu, Sep 2, 2021 at 12:04 PM Michael Santana <[email protected]> wrote: > > > On 8/26/21 11:45 AM, Sergey Madaminov wrote: > > Currently, the function call type cast for getting file handle > > produces a warning during OvS compilation on Windows with the following > > message: > > > > ``` > > ..\include\windows\unistd.h:97:25: warning: cast from function call of > type > > 'intptr_t' (aka 'int') to non-matching type 'HANDLE' (aka 'void *') > > [-Wbad-function-cast] > > HANDLE h = (HANDLE) _get_osfhandle(fd); > > ``` > > > > There is a function `LongToHandle()` to perform such cast [1]. > > But as `intptr_t` can be either `long long` for 64-bit or `int` for > > 32-bit, instead of clogging the code with `#ifdef` macros to use > > different cast functions, we can perform this cast directly. > > > > Signed-off-by: Sergey Madaminov <[email protected]> > > > > --- > > include/windows/unistd.h | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/include/windows/unistd.h b/include/windows/unistd.h > > index 21cc56ff1..62ff90a3f 100644 > > --- a/include/windows/unistd.h > > +++ b/include/windows/unistd.h > > @@ -94,7 +94,7 @@ __inline long sysconf(int type) > > static __inline int > > rpl_isatty(int fd) > > { > > - HANDLE h = (HANDLE) _get_osfhandle(fd); > > + HANDLE h = (HANDLE)(INT_PTR) _get_osfhandle(fd); > I dont have a windows machine handy to test INT_PTR so I did what I > could to test it on a little snippet test code on my 64 bit linux machine. > > void* bar = (void*) (int64_t*) myfunc32(foo); > This still warns me about -Wbad-function-cast > > void* bar = (void*) (int64_t*) (int64_t) myfunc32(foo); > This does not warn me about -Wbad-function-cast. Is this how INT_PTR > behaves on windows? It first casts to the correct size and then cast to > pointer of that size as well like shown above? > > DWORD st; > > return (_isatty(STDOUT_FILENO) > > && h != INVALID_HANDLE_VALUE > > > > _______________________________________________ dev mailing list [email protected] https://mail.openvswitch.org/mailman/listinfo/ovs-dev
