In article <3ebcc5d1-a57d-a290-72d8-6efc73025...@gmx.com>, Kamil Rytarowski <n...@gmx.com> wrote: >-=-=-=-=-=- >-=-=-=-=-=- > >On 11.08.2019 02:56, Valery Ushakov wrote: >> Kamil Rytarowski <n...@gmx.com> wrote: >> >>> Cast of udata from void* to intptr_t shall be done with >>> reinterpret_cast<> otherwise a C++ compiler errors. >>> >>> Defining __REINTERPRET_CAST [1] and using it, did not work as a compiler >>> protested for NULL argument "warning: passing NULL to non-pointer argument". >>> >>> Using double cast __REINTERPRET_CAST(intptr_t, __CAST(void *, (udata))) >>> pacified the warning/error about passing NULL in C++, but it created the >>> problem of calling EV_SET using the native argument type intptr_t. >> >> You are reporting quite an abstract summary that is not so easy to >> follow for someone who hasn't done all the same experiments that you >> already have done. > > >$ cat /tmp/test.cpp > > >#include <sys/types.h> >#include <sys/event.h> > >int >main(int argc, char **argv) >{ > struct kevent kv; > > EV_SET(&kv, 0, 0, 0, 0, 0, 0); > EV_SET(&kv, 0, 0, 0, 0, 0, NULL); > EV_SET(&kv, 0, 0, 0, 0, 0, nullptr); > EV_SET(&kv, 0, 0, 0, 0, 0, 0L); > EV_SET(&kv, 0, 0, 0, 0, 0, 0LL); > EV_SET(&kv, 0, 0, 0, 0, 0, 0U); > EV_SET(&kv, 0, 0, 0, 0, 0, 0UL); > EV_SET(&kv, 0, 0, 0, 0, 0, 0ULL); > EV_SET(&kv, 0, 0, 0, 0, 0, (intptr_t)0); > EV_SET(&kv, 0, 0, 0, 0, 0, (uintptr_t)0); > > > return 0; >}
How about: EV_SET(&kv, 0, 0, 0, 0, 0, 'a'); EV_SET(&kv, 0, 0, 0, 0, 0, 0.0); and all the other integral types not mentiones above? So if we are going to go gung ho C++, why not do it as a template? You could also possibly use std::is_integral (or the c++17 std::is_integral_v) etc., and perhaps get rid of the diagnostic suppression :-) christos