tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: EV_SET() better C++ compat with alternative implementations



On 11.08.2019 14:34, Christos Zoulas wrote:
> In article <3ebcc5d1-a57d-a290-72d8-6efc73025985%gmx.com@localhost>,
> Kamil Rytarowski  <n54%gmx.com@localhost> wrote:
>> -=-=-=-=-=-
>> -=-=-=-=-=-
>>
>> On 11.08.2019 02:56, Valery Ushakov wrote:
>>> Kamil Rytarowski <n54%gmx.com@localhost> 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');
This was handled.

>         EV_SET(&kv, 0, 0, 0, 0, 0, 0.0);
> 

This is handled in the newer version (to some extend) as it is converted
to intptr_t.

> 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?

I have managed to get it to work with templates compatible with c++98
and newer C++. This code eliminates all g++ and clang++ warnings.

http://netbsd.org/~kamil/patch-00137-EV_SET-template.txt

There is one template fallback for c++11 or newer for std::nullptr_t.

> 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 :-)
> 

Compatibility with C++98 is a must in headers.

> christos
> 


Attachment: signature.asc
Description: OpenPGP digital signature



Home | Main Index | Thread Index | Old Index