The types "const struct timeval *" and "struct timeval * const" are
not the same.  The first type is a pointer to a timeval struct that
the compiler should not try to modify, or at least it shouldn't modify
that struct through this particular pointer.  The second type is just
a pointer to an ordinary timeval struct, and for some reason the
compiler decided that the pointer itself is const, but not the thing
it is pointing to.

In Linux, argument 5 of select is a "struct timeval *" because Linux
actually writes to the struct.

In Mac OS X, argument 5 of select is a "struct timeval *", but Mac OS
X does not write to it.

In MSVC, argument 5 of select is a "const struct timeval *", and (as
we would expect) the implementation does not write to the struct.

In mingw-w64 (line 995 of winsock2.h), argument 5 of select is a
"const PTIMEVAL", which GCC is interpreting that to be "struct timeval
* const" according to the error message.  So that's the problem.
Corinna's commit e7b1c8ff in 2012 changed the argument from "const
struct timeval *" to "const PTIMEVAL", which are different types and
causes this warning for Glenn.  To fix this, a new type called
something like PCTIMEVAL could be introduced in _ip_types.h.  This
would make mingw-w64 more compatible with programs written for MSVC.
It shouldn't affect any programs written for Mac OS X or Linux.

--David

On Wed, Oct 28, 2015 at 9:50 AM, Burkhardt, Glenn B        UTAS
<[email protected]> wrote:
> There was a patch made to _ip_types.h and winsock.h in 2012 that I wish had 
> been made differently.  All the function prototypes using timeval* were 
> changed to use PTIMEVAL.  I think it would have been better to change the 
> typedef for 'timeval' for LP64 instead.
>
> I'm working with a library, which, for better or for worse, uses a cast for 
> the final argument in 'select'.  So with -Wall, the code:
>
> #include <time.h>
> #include <windows.h>
>
> void sub()
> {
>     struct timeval tv;
>
>     select(0, 0, 0, 0, (const struct timeval *)&tv);
> }
>
> gets a warning:
>
> tt.c: In function 'sub':
> tt.c:8:24: warning: passing argument 5 of 'select' discards 'const' qualifier 
> from pointer target type [-Wdiscarded-qualifiers]
>      select(0, 0, 0, 0, (const struct timeval *)&tv);
>                         ^
> In file included from 
> C:/TDM-GCC-64-5.1.0-2/x86_64-w64-mingw32/include/windows.h:92:0,
>                  from tt.c:2:
> C:/TDM-GCC-64-5.1.0-2/x86_64-w64-mingw32/include/winsock.h:299:34: note: 
> expected 'PTIMEVAL {aka struct timeval * const}' but argument is of type 
> 'const struct timeval *'
>    WINSOCK_API_LINKAGE int WSAAPI select(int nfds,fd_set *readfds,fd_set 
> *writefds,fd_set *exceptfds,const PTIMEVAL timeout);
>
> 'gcc' has never been good enough to treat "equal" type declarations as the 
> "same" when checking for this sort of error.
>
> ------------------------------------------------------------------------------
> _______________________________________________
> Mingw-w64-public mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

------------------------------------------------------------------------------
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to