C++ syntax error fixes
cover C++ syntax error fixes
This set of changes addresses compile-time problems encountered when including <ell/ell.h> in C++ code. The errors may be reproduced from the top-level ELL source directory with g++ like so:
g++ -I. -fsyntax-only ell/ell.h
Ossama Othman (2):
util: Fix C++ invalid pointer conversion
ell: Do not use C99 static array index in C++
ell/icmp6.h | 4 ++++ ell/rtnl.h | 4 ++++ ell/util.h | 4 ++-- 3 files changed, 10 insertions(+), 2 deletions(-)
Signature · 1 line
2.25.1
PATCH 1/2 util: Fix C++ invalid pointer conversion
Cast the void* arguments of l_secure_memcmp() to uint8_t* during assignment to the latter. C++ doesn't allow assignment of a void* to a pointer of another type without a cast. This allows <ell/util.h> to once again be used in C++ code.
--- ell/util.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
ell/util.h +2 -2
@@ -351,8 +351,8 @@ const char *l_util_get_debugfs_path(void);static inline int l_secure_memcmp (const void *a,const void *b,size_t size) { -const volatile uint8_t *aa = a; -const volatile uint8_t *bb = b; +const volatile uint8_t *aa = (const uint8_t *) a; +const volatile uint8_t *bb = (const uint8_t *) b;int res =0 , diff, mask;/*
Signature · 1 line
2.25.1
PATCH 2/2 ell: Do not use C99 static array index in C++
In reply to Ossama OthmanSome function declarations that are in the public ELL API that have an array parameter with a C99 static array size, e.g.
void foo(int a[static 4], result in compile-time errors when used in C++ code since C++ does not support that syntax. When using a C++ compiler, pass the array by reference to achieve a similar affect of having the compiler detect an inappropriately sized array being passed to the function in question.
Note: The use of a C++ reference to an array as a function parameter is not strictly the same as the C99 feature where the array size in the function parameter is declared static since the latter specifies a minimum array size and the the former specifies an exact size. However, that isn't a problem in the case of the changes in this patch since arrays of the exact size specified in the declaration are expected.
--- ell/icmp6.h | 4 ++++ ell/rtnl.h | 4 ++++ 2 files changed, 8 insertions(+)
ell/icmp6.h +4 -0
@@ -59,7 +59,11 @@ bool l_icmp6_client_set_debug(struct l_icmp6_client *client,l_icmp6_debug_cb_t function, void *user_data, l_icmp6_destroy_cb_t destroy);bool l_icmp6_client_set_address (struct l_icmp6_client *client, +#ifdef __cplusplus + const uint8_t (&addr)[6]); +#else const uint8_t addr[static 6]); +#endif bool l_icmp6_client_set_nodelay (struct l_icmp6_client *client,bool nodelay);bool l_icmp6_client_set_rtnl (struct l_icmp6_client *client,struct l_netlink *rtnl);
ell/rtnl.h +4 -0
@@ -79,7 +79,11 @@ uint32_t l_rtnl_set_linkmode_and_operstate(struct l_netlink *rtnl, int ifindex, l_netlink_destroy_func_t destroy); uint32_t l_rtnl_set_mac(struct l_netlink *rtnl, int ifindex, +#ifdef __cplusplus + const uint8_t (&addr)[6], +#else const uint8_t addr[static 6], +#endif bool power_up, l_netlink_command_func_t cb, void *user_data,
Signature · 1 line
2.25.1