[Mingw-users] socklen_t data type

Back to archive index
Eli Zaretskii eliz****@gnu*****
Tue Jun 30 23:23:03 JST 2020


> From: Keith Marshall <keith****@users*****>
> Date: Tue, 30 Jun 2020 07:54:18 +0100
> 
> > GDB is a C++ program these days, and is compiled with -fpermissive, so
> > this causes errors.
> 
> Surely -fpermissive relaxes the error checking for type conflicts,
> (possibly among other conditions -- I don't know what its scope is), so
> such errors would be downgraded to warnings.  Do you, perhaps, mean that
> GDB is compiled _without_ -fpermissive?

You are probably right.  All I know is that g++ emitted this:

    CXX    remote-utils.o
  remote-utils.cc: In function 'void handle_accept_event(int, gdb_client_data)':
  remote-utils.cc:146:69: error: invalid conversion from 'socklen_t*' {aka 'unsigned int*'} to 'int*' [-fpermissive]
    146 |   remote_desc = accept (listen_desc, (struct sockaddr *) &sockaddr, &len);
	|                                                                     ^~~~
	|                                                                     |
	|                                                                     socklen_t* {aka unsigned int*}

I guess I mis-interpreted what that confusing message means to say.

> There's more to it.  As I reported in:
> 
>    https://savannah.gnu.org/bugs/?57725
> 
> a primary motivator for the change to unsigned socklen_t was to avoid a
> proliferation of casts in <wspiapi.h>, (of which, at the time, I seemed
> to be writing quite a number).  Reviewing it again, I seem to have ended
> up with only one such cast which remains necessary, at line 917:
> 
>    if( (sa == NULL) || (len < sizeof( struct sockaddr )) )
> 
> With reversion to signed socklen_t, this should become:
> 
>    if( (sa == NULL) || (len < (socklen_t)(sizeof( struct sockaddr ))) )

You are a better judge of this, but to my mind a single cast is a
small price to pay for avoiding the kind of mess I faced yesterday,
with socklen_t popping up in compilation errors left and right.

Gnulib already removed the unnecessary conflicting typedef, and I will
shortly report the problem in the GDB sources to its developers.  But
I think the problems with code which assumes the last argument of
'accept' and its ilk could be a 'socklen_t *' are a much harder nut,
and so going back to a signed int will be a good compromise.

Thanks.



More information about the MinGW-Users mailing list
Back to archive index