'const PTIMEVAL timeout' is 'struct timeval *const timeout', whose `const` is 
meaningless except in its definition (which is not seen here).
(Also be noted that Linux version of select() modifies the 'timeout' structure 
so a `const` MUST NOT be placed there.)

And here is the 'timeval' structure specification:
```
Microsoft version (quoted from Windows SDK v6.1 doc):

The timeval structure is used to specify time values. It is associated with the 
Berkeley Software Distribution (BSD) Time.h header file.

typedef struct timeval {
  long tv_sec;
  long tv_usec;
} timeval;
```
Linux version (quoted from man-pages 3.74):

The timeout
    The time structures involved are defined in <sys/time.h> and look like

        struct timeval {
            long    tv_sec;         /* seconds */
            long    tv_usec;        /* microseconds */
        };
```
POSIX 2001 version (quoted from Linux man-pages 3.74):

the structure is defined in <sys/time.h>.  The POSIX.1-2001 situation is

    struct timeval {
        time_t         tv_sec;     /* seconds */
        suseconds_t    tv_usec;    /* microseconds */
    };

------------------                               
lh_mouse
2015-10-31

-------------------------------------------------------------
发件人:"Burkhardt, Glenn B        UTAS" <[email protected]>
发送日期:2015-10-30 20:21
收件人:[email protected]
抄送:
主题:Re: [Mingw-w64-public] [patch] Replace struct timeval usage

> 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



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

Reply via email to