On Tue, Mar 31, 2020 at 11:24 PM Martin Pieuchot <m...@openbsd.org> wrote:

> The current form of EV_SET(2) declares a `kevp' variable.  This can
> cause to subtle bugs hard to discover if one uses a variable of the
> same to retrieve events.
>
> Diff below prefixes the locally declared variable by an underscore,
> like it it done in FD_ZERO(), which should be good enough to prevent
> surprises.
>
> Is it the right way to correct such issue?  How many underscores are
> enough?  Can the standards gurus tell me?
>

tl;dr: this should use a variable that starts with either two underbars
(__kevp) or an underbar and a capital (_Kevp).  The same is true of
FD_ZERO().

The namespace of identifiers that begin with a single underbar is only
"reserved for use as identifiers with file scope in both the ordinary and
tag name spaces".  That means it's perfectly legal for an application to
declare a *local* variable with such a name.  So, this should be legal:

#include <sys/types.h>
#include <sys/event.h>
#include <sys/time.h>
#include <sys/select.h>
int main(void)
{
        struct fd_set _p;
        struct kevent _kevp;
        FD_ZERO(&_p):
        EV_SET(&_kevp, 0, 0, 0, 0, 0, 0);
        return 0;
}


...but it currently blows up on the FD_ZERO() and would blow up in the
EV_SET() with your proposed diff.


Philip Guenther

Reply via email to