0

I have a kevent ev and a int sock = socket(...). When I did ev.ident == sock, the g++47 warned me that warning: comparison between signed and unsigned integer expressions [-Wsign-compare]. What's wrong in my approach??

GuLearn
  • 1,814
  • 2
  • 18
  • 32
  • After checking both the FreeBSD manual page and some example, it seems that's how you're supposed to do. So there's nothing wrong with your approach. You might want to cast one or the other though (I suggest the socket), to get rid of the warning. – Some programmer dude May 23 '13 at 18:41
  • Is the kevent designed so on purpose, or just careless minor mistake? I thought ev.ident is expected to be used as a *file descriptor*, how could it have different type than *a file descripor*?? – GuLearn May 23 '13 at 18:46

1 Answers1

2

If you check the type, it's of type uintptr_t which is a standard type big enough to hold both the largest integer or a pointer. This is so it can be used on any kind of type which can easily be casted as an integer. And from the FreeBSD kqueue manual page:

Value used to identify this event. The exact interpretation is determined by the attached filter, but often is a file descriptor.

So I would definitely say it's by design.

If you want to get rid of the warning, I suggest yo cast the socket:

ev.ident == static_cast<uintptr_t>(sock)
Some programmer dude
  • 400,186
  • 35
  • 402
  • 621