Subject: Re: INVALID_SOCKET symbol conflict

Re: INVALID_SOCKET symbol conflict

From: Alexander Lamaison <swish_at_lammy.co.uk>
Date: Fri, 2 Mar 2012 16:27:45 +0000

On 2 March 2012 16:12, Lawson <lawson08_at_yahoo.com> wrote:
> Hi,
>
> Thanks for the prompt reply.  The compile warning is:
>
> In file included from /usr/local/include/libssh2/libssh2.h:140:1: warning: "INVALID_SOCKET" redefined
> In file included from /usr/local/include/snmp_pp/snmp_pp.h:71,
>                 from snmpThreadData.h:13,
>                 from snmpThreadData.cpp:4:
>
> /usr/local/include/snmp_pp/uxsnmp.h:49:1: warning: this is the location of the previous definition
>
> So the conflict is I end up with headers both from libssh2 and the snmp++ library (http://www.agentpp.com/snmp_pp3_x/snmp_pp3_x.html).
>
> Libssh2 defines it as:
>
> #define INVALID_SOCKET -1
>
> and SNMP++ defines it as:
> #ifndef INVALID_SOCKET
> #define INVALID_SOCKET ((SnmpSocket)(~0)) // value for invalid socket
> #endif

I believe that both these values actually result in the same thing: an
int-size chunk of memory with all bits set.

> Note that the SNMP++ header has an #ifdef.

One way to deal with this is to do the same thing so whichever one
comes first wins.

> Mostly I was perplexed at why two different libraries which are otherwise both disciplined about defining their constants with a namespace prefix both chose to define this one symbol like this, like it was some magical special symbol that everyone  knew about.

I guess it *is* a magical special symbol everyone knows about ... if
you come from the Windows world.

My personal preference would be to declare our own constant, something
like LIBSSH2_INVALID_SOCKET that is INVALID_SOCKET on windows and -1
elsewhere. Then we use that in the libssh2 source code rather than
co-opting INVALID_SOCKET.

Alex

--
Easy SFTP for Windows Explorer (http://www.swish-sftp.org)
_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Received on 2012-03-02