From: Patrick Ohly <patrick.ohly@intel.com>
To: Marcel Holtmann <marcel@holtmann.org>
Cc: linux-bluetooth@vger.kernel.org, Milan Crha <mcrha@redhat.com>,
ying.an.deng@intel.com, ulf.hofemeier@intel.com,
ning.w.wang@intel.com,
Tino Keitel <tino.keitel+syncevolution@tikei.de>,
Rohan Garg <rohan16garg@gmail.com>
Subject: [PATCH] bluetooth.h: fix compile issue in C++ with ifdef
Date: Sun, 05 Feb 2012 11:57:44 +0100 [thread overview]
Message-ID: <1328439464.32199.22.camel@pohly-mobl1.fritz.box> (raw)
In-Reply-To: <1328439363.32199.20.camel@pohly-mobl1.fritz.box>
The compiler error is:
/usr/include/bluetooth/bluetooth.h::131:9: error: invalid conversion from 'void*' to 'bt_get_le64(void*)::<anonymous struct>*'
...
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.
This patch keeps the "struct __attribute__((packed))" magic and merely
changes the typecast so that it works in C and C++. Like the existing
macro this patch relies on support for typeof.
The new variant of the code is in an ifdef and only used for C++
to avoid unexpected regressions in C applications.
Signed-off-by: Patrick Ohly <patrick.ohly@intel.com>
---
lib/bluetooth.h | 30 ++++++++++++++++++++++++++++++
1 files changed, 30 insertions(+), 0 deletions(-)
diff --git a/lib/bluetooth.h b/lib/bluetooth.h
index 5bd4f03..3293915 100644
--- a/lib/bluetooth.h
+++ b/lib/bluetooth.h
@@ -109,6 +109,11 @@ enum {
#endif
/* Bluetooth unaligned access */
+#ifndef __cplusplus
+/*
+ * traditional code, doesn't work in C++ because
+ * of the void * to struct pointer assignment
+ */
#define bt_get_unaligned(ptr) \
({ \
struct __attribute__((packed)) { \
@@ -125,6 +130,31 @@ do { \
__p->__v = (val); \
} while(0)
+#else /* __cplusplus */
+
+/*
+ * modified code with typeof typecast, for C++;
+ * the traditional code continues to be used for
+ * C to avoid unexpected regressions with this
+ * code here (it should work in C and C++, though)
+ */
+#define bt_get_unaligned(ptr) \
+({ \
+ struct __attribute__((packed)) { \
+ typeof(*(ptr)) __v; \
+ } *__p = (typeof(__p)) (ptr); \
+ __p->__v; \
+})
+
+#define bt_put_unaligned(val, ptr) \
+do { \
+ struct __attribute__((packed)) { \
+ typeof(*(ptr)) __v; \
+ } *__p = (typeof(__p)) (ptr); \
+ __p->__v = (val); \
+} while(0)
+#endif /* __cplusplus */
+
#if __BYTE_ORDER == __LITTLE_ENDIAN
static inline uint64_t bt_get_le64(void *ptr)
{
--
1.7.8.3
next prev parent reply other threads:[~2012-02-05 10:57 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-16 8:25 bluez 4.97: build failure when used in C++ apps Patrick Ohly
2012-01-16 8:48 ` Deng, Ying An
2012-01-16 9:24 ` Marcel Holtmann
2012-01-16 10:09 ` Patrick Ohly
2012-02-05 10:56 ` Patrick Ohly
2012-02-05 10:57 ` Patrick Ohly [this message]
2012-02-05 11:07 ` [PATCH] bluetooth.h: fix compile issue in C++ with ifdef Rohan Garg
2012-02-05 11:33 ` Patrick Ohly
2012-02-05 11:33 ` Rohan Garg
2012-02-05 12:23 ` Rohan Garg
2012-02-05 12:28 ` Rohan Garg
2012-02-05 10:59 ` bluez 4.97: build failure when used in C++ apps Rohan Garg
2012-02-05 12:02 ` Rohan Garg
2012-02-06 8:46 ` Milan Crha
2012-02-06 9:29 ` Patrick Ohly
2012-02-06 9:51 ` Milan Crha
2012-02-05 14:29 ` Tino Keitel
2012-02-05 14:50 ` Rohan Garg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1328439464.32199.22.camel@pohly-mobl1.fritz.box \
--to=patrick.ohly@intel.com \
--cc=linux-bluetooth@vger.kernel.org \
--cc=marcel@holtmann.org \
--cc=mcrha@redhat.com \
--cc=ning.w.wang@intel.com \
--cc=rohan16garg@gmail.com \
--cc=tino.keitel+syncevolution@tikei.de \
--cc=ulf.hofemeier@intel.com \
--cc=ying.an.deng@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).