This is the mail archive of the cygwin mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

bug in <sys/un.h>

STC - this program does nothing useful when executed; it merely exists
to show a compilation problem extracted from a larger program:

$ cat foo.c
# include <sys/socket.h>
#include <sys/un.h>
#include <sys/socket.h>
int main(void) {
  const struct msghdr msg;
  return sendmsg(0, &msg, 0);
$ gcc -o foo -Wall foo.c
foo.c: In function 'main':
foo.c:9:5: warning: passing argument 2 of 'sendmsg' from incompatible
pointer type
/usr/include/sys/socket.h:42:11: note: expected 'const struct msghdr *'
but argument is of type 'const struct msghdr *'
$ gcc -o foo -Wall foo.c -DWORKAROUND

Gcc has a less-than-stellar error message (expect type X but have type
X); it could do a better job about pointing out that it is complaining
about two different 'type X' declarations, and where they come from.
But the root cause is that if <sys/un.h> is included first, then the use
of 'struct msghdr' applied in the declaration of sendmsg() is somehow
scoped incorrectly (local to the declaration rather than the global
type), so that the compiler really is complaining about two different
incompatible 'struct msghdr' layouts.  I'm not quite sure what the fix
should be, but since I hit the problem today, I'm at least pointing it
out.  The same test case compiles without needing a workaround on Linux
with glibc 2.16.

Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library

Attachment: signature.asc
Description: OpenPGP digital signature

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]