Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 23 Dec 2019 16:55:10 +0300
From:      Slawa Olhovchenkov <slw@zxy.spb.ru>
To:        Ryan Stone <rysto32@gmail.com>
Cc:        freebsd-stable@freebsd.org
Subject:   Re: Access to NETMAP from c++ program
Message-ID:  <20191223135509.GE38096@zxy.spb.ru>
In-Reply-To: <CAFMmRNyxJtDdnP1VbJkwFQaR0gMoeOE2OpO_VjC43xWmNh7x%2Bg@mail.gmail.com>
References:  <20191119213319.GD38096@zxy.spb.ru> <CAFMmRNyxJtDdnP1VbJkwFQaR0gMoeOE2OpO_VjC43xWmNh7x%2Bg@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, Nov 25, 2019 at 03:36:21PM -0500, Ryan Stone wrote:

> Remove "using namespace std;" from your program.

I am don't have "using namespace std;".

Example:

===
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <net/netmap_user.h>
===

Yes, only includes.

c++ -c tatomic.cc
In file included from tatomic.cc:11:
In file included from /usr/include/net/netmap_user.h:104:
In file included from /usr/include/net/netmap.h:816:
/usr/include/stdatomic.h:186:17: error: unknown type name '_Bool'
typedef _Atomic(_Bool)                  atomic_bool;
                ^
/usr/include/stdatomic.h:186:26: error: C++ requires a type specifier for all declarations
typedef _Atomic(_Bool)                  atomic_bool;
~~~~~~                                 ^
/usr/include/stdatomic.h:379:17: error: unknown type name '_Bool'
static __inline _Bool
                ^
/usr/include/stdatomic.h:383:10: error: address argument to atomic operation must be a pointer to _Atomic type ('volatile atomic_bool *' (aka 'volatile int *') invalid)
        return (atomic_exchange_explicit(&__object->__flag, 1, __order));
                ^                        ~~~~~~~~~~~~~~~~~
/usr/include/stdatomic.h:242:2: note: expanded from macro 'atomic_exchange_explicit'
        __c11_atomic_exchange(object, desired, order)
        ^                     ~~~~~~
/usr/include/stdatomic.h:390:2: error: address argument to atomic operation must be a pointer to _Atomic type ('volatile atomic_bool *' (aka 'volatile int *') invalid)
        atomic_store_explicit(&__object->__flag, 0, __order);
        ^                     ~~~~~~~~~~~~~~~~~
/usr/include/stdatomic.h:256:2: note: expanded from macro 'atomic_store_explicit'
        __c11_atomic_store(object, desired, order)
        ^                  ~~~~~~
/usr/include/stdatomic.h:394:17: error: unknown type name '_Bool'
static __inline _Bool
                ^
6 errors generated.

Ok, try ugly hack for _Bool:

===
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/types.h>
typedef        int     _Bool;
#include <net/netmap_user.h>
===

No, errors. Now try <atomic>

===
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/types.h>
typedef        int     _Bool;
#include <net/netmap_user.h>
#include <memory>
#include <atomic>
===

Many errors:
In file included from tatomic.cc:13:
In file included from /usr/include/c++/v1/memory:668:
/usr/include/c++/v1/atomic:1166:49: error: expected ')'
atomic_is_lock_free(const volatile atomic<_Tp>* __o) _NOEXCEPT
                                                ^
/usr/include/c++/v1/atomic:1166:1: note: to match this '('
atomic_is_lock_free(const volatile atomic<_Tp>* __o) _NOEXCEPT
^
/usr/include/stdatomic.h:176:32: note: expanded from macro 'atomic_is_lock_free'
        __atomic_is_lock_free(sizeof(*(obj)), obj)
                                      ^
In file included from tatomic.cc:13:
In file included from /usr/include/c++/v1/memory:668:
/usr/include/c++/v1/atomic:1166:1: error: expected expression
atomic_is_lock_free(const volatile atomic<_Tp>* __o) _NOEXCEPT
^
/usr/include/stdatomic.h:176:37: note: expanded from macro 'atomic_is_lock_free'
        __atomic_is_lock_free(sizeof(*(obj)), obj)
                                           ^
In file included from tatomic.cc:13:
In file included from /usr/include/c++/v1/memory:668:
/usr/include/c++/v1/atomic:1166:21: error: expected expression
atomic_is_lock_free(const volatile atomic<_Tp>* __o) _NOEXCEPT
                    ^
/usr/include/c++/v1/atomic:1166:53: error: expected ';' at end of declaration
atomic_is_lock_free(const volatile atomic<_Tp>* __o) _NOEXCEPT
                                                    ^
/usr/include/c++/v1/atomic:1166:54: error: expected unqualified-id
atomic_is_lock_free(const volatile atomic<_Tp>* __o) _NOEXCEPT
                                                     ^
/usr/include/c++/v1/__config:839:21: note: expanded from macro '_NOEXCEPT'
#  define _NOEXCEPT noexcept
                    ^
In file included from tatomic.cc:13:
In file included from /usr/include/c++/v1/memory:668:
/usr/include/c++/v1/atomic:1174:1: error: redefinition of '__atomic_is_lock_free'
atomic_is_lock_free(const atomic<_Tp>* __o) _NOEXCEPT
^
/usr/include/stdatomic.h:176:2: note: expanded from macro 'atomic_is_lock_free'
        __atomic_is_lock_free(sizeof(*(obj)), obj)
        ^
/usr/include/c++/v1/atomic:1166:1: note: previous definition is here
atomic_is_lock_free(const volatile atomic<_Tp>* __o) _NOEXCEPT
^
/usr/include/stdatomic.h:176:2: note: expanded from macro 'atomic_is_lock_free'
        __atomic_is_lock_free(sizeof(*(obj)), obj)
        ^
In file included from tatomic.cc:13:
In file included from /usr/include/c++/v1/memory:668:
/usr/include/c++/v1/atomic:1174:40: error: expected ')'
atomic_is_lock_free(const atomic<_Tp>* __o) _NOEXCEPT
                                       ^
/usr/include/c++/v1/atomic:1174:1: note: to match this '('
atomic_is_lock_free(const atomic<_Tp>* __o) _NOEXCEPT
^
/usr/include/stdatomic.h:176:32: note: expanded from macro 'atomic_is_lock_free'
        __atomic_is_lock_free(sizeof(*(obj)), obj)
                                      ^
In file included from tatomic.cc:13:
In file included from /usr/include/c++/v1/memory:668:
/usr/include/c++/v1/atomic:1174:1: error: expected expression
atomic_is_lock_free(const atomic<_Tp>* __o) _NOEXCEPT
^
/usr/include/stdatomic.h:176:37: note: expanded from macro 'atomic_is_lock_free'
        __atomic_is_lock_free(sizeof(*(obj)), obj)
                                           ^
In file included from tatomic.cc:13:
In file included from /usr/include/c++/v1/memory:668:
/usr/include/c++/v1/atomic:1174:21: error: expected expression
atomic_is_lock_free(const atomic<_Tp>* __o) _NOEXCEPT
                    ^
/usr/include/c++/v1/atomic:1174:44: error: expected ';' at end of declaration
atomic_is_lock_free(const atomic<_Tp>* __o) _NOEXCEPT
                                           ^
/usr/include/c++/v1/atomic:1174:45: error: expected unqualified-id
atomic_is_lock_free(const atomic<_Tp>* __o) _NOEXCEPT
                                            ^
/usr/include/c++/v1/__config:839:21: note: expanded from macro '_NOEXCEPT'
#  define _NOEXCEPT noexcept
                    ^
In file included from tatomic.cc:13:
In file included from /usr/include/c++/v1/memory:668:
/usr/include/c++/v1/atomic:1202:1: error: unknown type name 'memory_order_seq_cst'
atomic_store(volatile atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
^
/usr/include/stdatomic.h:363:41: note: expanded from macro 'atomic_store'
        atomic_store_explicit(object, desired, memory_order_seq_cst)
                                               ^
In file included from tatomic.cc:13:
In file included from /usr/include/c++/v1/memory:668:
/usr/include/c++/v1/atomic:1210:1: error: unknown type name 'memory_order_seq_cst'
atomic_store(atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
^
/usr/include/stdatomic.h:363:41: note: expanded from macro 'atomic_store'
        atomic_store_explicit(object, desired, memory_order_seq_cst)
                                               ^
In file included from tatomic.cc:13:
In file included from /usr/include/c++/v1/memory:668:
/usr/include/c++/v1/atomic:1240:1: error: unknown type name 'memory_order_seq_cst'
atomic_load(const volatile atomic<_Tp>* __o) _NOEXCEPT
^
/usr/include/stdatomic.h:361:31: note: expanded from macro 'atomic_load'
        atomic_load_explicit(object, memory_order_seq_cst)
                                     ^
In file included from tatomic.cc:13:
In file included from /usr/include/c++/v1/memory:668:
/usr/include/c++/v1/atomic:1248:1: error: unknown type name 'memory_order_seq_cst'
atomic_load(const atomic<_Tp>* __o) _NOEXCEPT
^
/usr/include/stdatomic.h:361:31: note: expanded from macro 'atomic_load'
        atomic_load_explicit(object, memory_order_seq_cst)
                                     ^
In file included from tatomic.cc:13:
In file included from /usr/include/c++/v1/memory:668:
/usr/include/c++/v1/atomic:1278:1: error: unknown type name 'memory_order_seq_cst'
atomic_exchange(volatile atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
^
/usr/include/stdatomic.h:349:44: note: expanded from macro 'atomic_exchange'
        atomic_exchange_explicit(object, desired, memory_order_seq_cst)
                                                  ^
In file included from tatomic.cc:13:
In file included from /usr/include/c++/v1/memory:668:
/usr/include/c++/v1/atomic:1286:1: error: unknown type name 'memory_order_seq_cst'
atomic_exchange(atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
^
/usr/include/stdatomic.h:349:44: note: expanded from macro 'atomic_exchange'
        atomic_exchange_explicit(object, desired, memory_order_seq_cst)
                                                  ^
In file included from tatomic.cc:13:
In file included from /usr/include/c++/v1/memory:668:
/usr/include/c++/v1/atomic:1314:1: error: C++ requires a type specifier for all declarations
atomic_compare_exchange_weak(volatile atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NOEXCEPT
^
/usr/include/stdatomic.h:347:15: note: expanded from macro 'atomic_compare_exchange_weak'
            desired, memory_order_seq_cst, memory_order_seq_cst)
                     ^
In file included from tatomic.cc:13:
In file included from /usr/include/c++/v1/memory:668:
/usr/include/c++/v1/atomic:1314:1: error: unknown type name 'memory_order_seq_cst'
/usr/include/stdatomic.h:347:37: note: expanded from macro 'atomic_compare_exchange_weak'
            desired, memory_order_seq_cst, memory_order_seq_cst)
                                           ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.

Try different order:

===
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <memory>
#include <atomic>
typedef        int     _Bool;
#include <net/netmap_user.h>
===

No errors, no ugly hack for _Bool required.

Is this normal?



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20191223135509.GE38096>