#6373 closed bug (fixed)
Bluetooth address macros are broken
Reported by: | zooey | Owned by: | oruizdorantes |
---|---|---|---|
Priority: | normal | Milestone: | R1 |
Component: | Network & Internet/Bluetooth | Version: | R1/alpha2 |
Keywords: | Cc: | ||
Blocked By: | Blocking: | ||
Platform: | All |
Description
The bluetooth.h header defines these bdaddr_t macros:
#define BDADDR_NULL (&(bdaddr_t) {{0, 0, 0, 0, 0, 0}}) #define BDADDR_LOCAL (&(bdaddr_t) {{0, 0, 0, 0xff, 0xff, 0xff}}) #define BDADDR_BROADCAST (&(bdaddr_t) {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}})
However, the concept of getting an address of a compound literal is pretty much broken, as compound literals are neither part of the C++ standard (though gcc supports them) and their lifetime is not well-controlled inside of a macro.
As an example:
struct foo { bdaddr_t peer; }; void bar() { foo myfoo; if (...) myfoo.peer = BDADDR_LOCAL; else myfoo.peer = BDADDR_NULL; // try doing something with myfoo, but the actuall bdaddr_t object will // be dead here already, so the data at the address myfoo.peer may have // been overwritten }
Instead, I suggest doing something along the lines of:
extern const bdaddr_t __BDADDR_NULL; extern const bdaddr_t __BDADDR_LOCAL; extern const bdaddr_t __BDADDR_BROADCAST; #define BDADDR_NULL (&__BDADDR_NULL) #define BDADDR_LOCAL (&__BDADDR_LOCAL) #define BDADDR_BROADCAST (&__BDADDR_BROADCAST)
and then define these constants somewhere in an implementation file that gets linked by all users of those macros.
Change History (4)
comment:1 by , 14 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:2 by , 14 years ago
Hi,
The problem of this solution is that these data needs to be explicitly instantiated in each module using it.
Have you tried declarig them inside the class(bdaddrUtils) as a static member? I wonder if this results in symbol duplication at linking.
Regards.
Should be fixed in hrev38213.