> The types "const struct timeval *" and "struct timeval * const" are not the
> same.
Right, of course. But there seems to be a fundamental limitation in gcc when
it comes to recognizing that two types are "equal". It appears that it
doesn't make that check.
Consider this code, which avoids using headers for clarity:
struct timeval {
long tv_sec; /* seconds */
long tv_usec; /* microseconds */
};
typedef unsigned int u_int;
typedef unsigned int * SOCKET;
typedef struct fd_set
{
u_int fd_count;
SOCKET fd_array[64];
} fd_set;
typedef struct timeval *PTIMEVAL;
int select(int nfds,fd_set *readfds,fd_set *writefds,fd_set *exceptfds,
const PTIMEVAL timeout);
void sub()
{
struct timeval tv;
select(0, 0, 0, 0, (const struct timeval *)&tv);
}
Both gcc 4.8.4 on Linux and TDM-GCC 5.1.0 give this warning:
t.c:21: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);
^
t.c:14:5: note: expected 'PTIMEVAL {aka struct timeval * const}' but argument
is of type 'const struct timeval *'
int select(int nfds,fd_set *readfds,fd_set *writefds,fd_set *exceptfds,
^
I can't explain why the other warning came out with "struct timeval * const".
But I think the long and the short of it is that using a typedef to switch to a
different 'timeval' structure instead of using conditionals to define different
'timeval' will cause this minor problem.
Ironically, the libncftp code that cast the 5th argument to select was probably
written simply to document the fact that the Microsoft edition of select
doesn't change the timer value, as Linux does. The code would compile without
warnings if the cast was simply dropped.
------------------------------------------------------------------------------
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public