>From 51f8b4d8343454b04e7ed83b7770185d718d6203 Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Mon, 16 Jan 2012 10:58:44 +0100 Subject: [PATCH] bluetooth.h: fix typecast and typeof compile issue when used in C++ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The compiler error for the typecast is: /usr/include/bluetooth/bluetooth.h::131:9: error: invalid conversion from 'void*' to 'bt_get_le64(void*)::*' ... The reason is that C++, in contrast to C, does not allow conversion of void * to anything, and this code gets compiled as C++ when the app is written in C++. The macro with the assignment itself is older, but only recent Bluez starts to use it in inline functions, thus triggering the problem. Another issue in combination with -std=c++0x is the use of typeof, which is not a standard C++ feature and thus gets rejected in strict mode. This patch keeps the "struct __attribute__((packed))" magic and merely changes the typecast so that it works in C and C++. typeof gets replaced with __typeof__. g++ 4.6.2 and clang++ 3.0-5 accept the modified header file, with and without -std=c++0x. gcc 4.6.2 accepts it without -std, with -std=gnu89, and with -std=c99. It rejects the header file with -std=c89 because of the inline keyword. Signed-off-by: Patrick Ohly --- lib/bluetooth.h | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/bluetooth.h b/lib/bluetooth.h index 5bd4f03..297d52d 100644 --- a/lib/bluetooth.h +++ b/lib/bluetooth.h @@ -112,16 +112,16 @@ enum { #define bt_get_unaligned(ptr) \ ({ \ struct __attribute__((packed)) { \ - typeof(*(ptr)) __v; \ - } *__p = (void *) (ptr); \ + __typeof__(*(ptr)) __v; \ + } *__p = (__typeof__(__p)) (ptr); \ __p->__v; \ }) #define bt_put_unaligned(val, ptr) \ do { \ struct __attribute__((packed)) { \ - typeof(*(ptr)) __v; \ - } *__p = (void *) (ptr); \ + __typeof__(*(ptr)) __v; \ + } *__p = (__typeof__(__p)) (ptr); \ __p->__v = (val); \ } while(0) -- 1.7.9