C / C ++ Warning: temporary library address BDADDR_ANY Bluetooth

I am having problems with g ++ and the compilation process for a C / C ++ program that uses the Bluetooth libraries in Ubuntu.

If I use gcc, it works fine without warning; conversely, if I use g ++, I get this warning:

warning: with temporary address

even if the program compiles and runs.

Related error reporting lines:

bdaddr_t *inquiry(){ // do some stuff.. bacpy(&result[mote++], BDADDR_ANY); return result; } //... void zeemote(){ while (bacmp(bdaddr, BDADDR_ANY)){ /.. } } 

In both cases, BDADDR_ANY is involved.

How can I resolve this warning?

BDADDR_ANY is defined in bluetooth.h as:

 /* BD Address */ typedef struct { uint8_t b[6]; } __attribute__((packed)) bdaddr_t; #define BDADDR_ANY (&(bdaddr_t) {{0, 0, 0, 0, 0, 0}}) 
+4
source share
2 answers
 (&(bdaddr_t) {{0, 0, 0, 0, 0, 0}}) 

Creates a temporary object and uses its address. This is not allowed in C ++.

You can fix this by creating a named temporary variable and using bacpy and bacmp on it:

 bdaddr_t tmp = { }; bacpy(&result[mote++], &tmp); 

and

 while (bacmp(bdaddr, &tmp)) { // } 
+4
source

Create a variable (in any area convenient), not a temporary one ...

 bdaddr_t my_bdaddr_any = { 0 }; while (bacmp(bdaddr, my_bdaddr_any)) ... 
+2
source

Source: https://habr.com/ru/post/1401999/


All Articles