[Privoxy-devel] incompatible pointer type
Fabian Keil
fk at fabiankeil.de
Thu Jan 10 15:51:13 UTC 2019
Lee <ler762 at gmail.com> wrote:
> On 1/9/19, Fabian Keil <fk at fabiankeil.de> wrote:
> > Lee <ler762 at gmail.com> wrote:
> >
> >> All pointers are the same size - correct?
> >
> > Correct.
> >
> >> I get a couple of warnings in jbsockets.c about incompatible pointer types
> >> - eg:
> >> jbsockets.c: In function ‘set_no_delay_flag’:
> >> jbsockets.c:140:49: warning: passing argument 4 of ‘setsockopt’ from
> >> incompatible pointer type [-Wincompatible-pointer-types]
> >> if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &mi, sizeof(int)))
> >> ^
> >> In file included from jbsockets.c:52:0:
> >> /usr/i686-w64-mingw32/sys-root/mingw/include/winsock2.h:999:34: note:
> >> expected ‘const char *’ but argument is of type ‘int *’
> >> WINSOCK_API_LINKAGE int WSAAPI setsockopt(SOCKET s,int level,int
> >> optname,const char *optval,int optlen);
> >> ^~~~~~~~~~
> >>
> >> that boils down to Windows expects a 'char*' pointer & *nix expects a
> >> 'int*' pointer.
> >
> > On ElectroBSD the prototype is:
> >
> > int
> > setsockopt(int s, int level, int optname, const void *optval,
> > socklen_t optlen);
>
> Which means you're not going to get a compiler warning on ElectroBSD if you have
> char* optval or int* optval? And either will work?
Either should "work" but it seems more appropriate to cast to "void *"
which should silence the error for you to.
> >> I can make the warnings go away by casting the 4th parameter to (char*)
> >> - if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &mi, sizeof(int)))
> >> + if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (char*)&mi,
> >> sizeof(int)))
> >>
> >> but a 'char*' pointer is the same size as an 'int*' pointer, so this
> >> is just a cosmetic issue that can safely be ignored. Correct?
> >
> > Correct.
>
> What's the expected expertise level of somebody looking at the code?
> As in, is it worth adding a comment that with the mingw gcc headers
> you're going to get a [-Wincompatible-pointer-types] warning from the
> compiler here & it's a cosmetic issue that isn't worth the effort to
> fix?
I don't think such a comment would be worth it.
Fabian
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <https://lists.privoxy.org/pipermail/privoxy-devel/attachments/20190110/5931afce/attachment.bin>
More information about the Privoxy-devel
mailing list