macro usage error
-
I am using the attached code , originally written in C , and receiving an error - related to usage of BDADDR_ANY macro - I do not understand and do not know how to fix it. Here is BDADDR_ANY macro
#define BDADDR_ANY (&(bdaddr_t) {{0, 0, 0, 0, 0, 0}})
#define BDADDR_ALL (&(bdaddr_t) {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}})
#define BDADDR_LOCAL (&(bdaddr_t) {{0, 0, 0, 0xff, 0xff, 0xff}})\
struct sockaddr\_rc loc\_addr; struct sockaddr\_rc rem\_addr; char buf\[1024\] = { 0 }; int s, client, bytes\_read; socklen\_t opt = sizeof(rem\_addr); // allocate socket s = socket(AF\_BLUETOOTH, SOCK\_STREAM, BTPROTO\_RFCOMM); // bind socket to port 1 of the first available // local bluetooth adapter loc\_addr.rc\_family = AF\_BLUETOOTH; // socket family loc\_addr.rc\_bdaddr = \*BDADDR\_ANY; // local address
/mnt/sde5/QT_PROGRAMS_FULL/MDI_BT/MDI_BT/SUB_FT857/mainwindow_sub_ft857.cpp:106: error: taking address of rvalue [-fpermissive]
In file included from /mnt/sde5/QT_PROGRAMS_FULL/LoCAL_SOURCE/BT_Utility_Library/concurrent.h:15,
from /mnt/sde5/QT_PROGRAMS_FULL/MDI_BT/MDI_BT/SUB_FT857/mainwindow_sub_ft857.h:17,
from /mnt/sde5/QT_PROGRAMS_FULL/MDI_BT/MDI_BT/SUB_FT857/mainwindow_sub_ft857.cpp:1:
/mnt/sde5/QT_PROGRAMS_FULL/MDI_BT/MDI_BT/SUB_FT857/mainwindow_sub_ft857.cpp: In member function ‘int MainWindow_SUB_FT857::Connect(QString)’:
/mnt/sde5/QT_PROGRAMS_FULL/MDI_BT/MDI_BT/SUB_FT857/mainwindow_sub_ft857.cpp:106:27: error: taking address of rvalue [-fpermissive]
106 | loc_addr.rc_bdaddr = *BDADDR_ANY;
| ^~~~~~~~~~actually there is another take on this error
" taking address of temporary value..."
( not sure why they differ )
loc\_addr.rc\_channel = (uint8\_t) 1; bind(s, (struct sockaddr \*)&loc\_addr, sizeof(loc\_addr)); // put socket into listening mode listen(s, 1); // accept one connection client = accept(s, (struct sockaddr \*)&rem\_addr, &opt); ba2str( &rem\_addr.rc\_bdaddr, buf ); fprintf(stderr, "accepted connection from %s\\n", buf); memset(buf, 0, sizeof(buf)); // read data from the client bytes\_read = read(client, buf, sizeof(buf)); if( bytes\_read > 0 ) { printf("received \[%s\]\\n", buf); }
Please any help to resolve this coding issue will be much appreciated.
-
I am using the attached code , originally written in C , and receiving an error - related to usage of BDADDR_ANY macro - I do not understand and do not know how to fix it. Here is BDADDR_ANY macro
#define BDADDR_ANY (&(bdaddr_t) {{0, 0, 0, 0, 0, 0}})
#define BDADDR_ALL (&(bdaddr_t) {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}})
#define BDADDR_LOCAL (&(bdaddr_t) {{0, 0, 0, 0xff, 0xff, 0xff}})\
struct sockaddr\_rc loc\_addr; struct sockaddr\_rc rem\_addr; char buf\[1024\] = { 0 }; int s, client, bytes\_read; socklen\_t opt = sizeof(rem\_addr); // allocate socket s = socket(AF\_BLUETOOTH, SOCK\_STREAM, BTPROTO\_RFCOMM); // bind socket to port 1 of the first available // local bluetooth adapter loc\_addr.rc\_family = AF\_BLUETOOTH; // socket family loc\_addr.rc\_bdaddr = \*BDADDR\_ANY; // local address
/mnt/sde5/QT_PROGRAMS_FULL/MDI_BT/MDI_BT/SUB_FT857/mainwindow_sub_ft857.cpp:106: error: taking address of rvalue [-fpermissive]
In file included from /mnt/sde5/QT_PROGRAMS_FULL/LoCAL_SOURCE/BT_Utility_Library/concurrent.h:15,
from /mnt/sde5/QT_PROGRAMS_FULL/MDI_BT/MDI_BT/SUB_FT857/mainwindow_sub_ft857.h:17,
from /mnt/sde5/QT_PROGRAMS_FULL/MDI_BT/MDI_BT/SUB_FT857/mainwindow_sub_ft857.cpp:1:
/mnt/sde5/QT_PROGRAMS_FULL/MDI_BT/MDI_BT/SUB_FT857/mainwindow_sub_ft857.cpp: In member function ‘int MainWindow_SUB_FT857::Connect(QString)’:
/mnt/sde5/QT_PROGRAMS_FULL/MDI_BT/MDI_BT/SUB_FT857/mainwindow_sub_ft857.cpp:106:27: error: taking address of rvalue [-fpermissive]
106 | loc_addr.rc_bdaddr = *BDADDR_ANY;
| ^~~~~~~~~~actually there is another take on this error
" taking address of temporary value..."
( not sure why they differ )
loc\_addr.rc\_channel = (uint8\_t) 1; bind(s, (struct sockaddr \*)&loc\_addr, sizeof(loc\_addr)); // put socket into listening mode listen(s, 1); // accept one connection client = accept(s, (struct sockaddr \*)&rem\_addr, &opt); ba2str( &rem\_addr.rc\_bdaddr, buf ); fprintf(stderr, "accepted connection from %s\\n", buf); memset(buf, 0, sizeof(buf)); // read data from the client bytes\_read = read(client, buf, sizeof(buf)); if( bytes\_read > 0 ) { printf("received \[%s\]\\n", buf); }
Please any help to resolve this coding issue will be much appreciated.
Hav a look at this discussion: [C/C++ Warning: address of temporary with BDADDR_ANY Bluetooth library - Stack Overflow](https://stackoverflow.com/questions/9751710/c-c-warning-address-of-temporary-with-bdaddr-any-bluetooth-library)
-
I am using the attached code , originally written in C , and receiving an error - related to usage of BDADDR_ANY macro - I do not understand and do not know how to fix it. Here is BDADDR_ANY macro
#define BDADDR_ANY (&(bdaddr_t) {{0, 0, 0, 0, 0, 0}})
#define BDADDR_ALL (&(bdaddr_t) {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}})
#define BDADDR_LOCAL (&(bdaddr_t) {{0, 0, 0, 0xff, 0xff, 0xff}})\
struct sockaddr\_rc loc\_addr; struct sockaddr\_rc rem\_addr; char buf\[1024\] = { 0 }; int s, client, bytes\_read; socklen\_t opt = sizeof(rem\_addr); // allocate socket s = socket(AF\_BLUETOOTH, SOCK\_STREAM, BTPROTO\_RFCOMM); // bind socket to port 1 of the first available // local bluetooth adapter loc\_addr.rc\_family = AF\_BLUETOOTH; // socket family loc\_addr.rc\_bdaddr = \*BDADDR\_ANY; // local address
/mnt/sde5/QT_PROGRAMS_FULL/MDI_BT/MDI_BT/SUB_FT857/mainwindow_sub_ft857.cpp:106: error: taking address of rvalue [-fpermissive]
In file included from /mnt/sde5/QT_PROGRAMS_FULL/LoCAL_SOURCE/BT_Utility_Library/concurrent.h:15,
from /mnt/sde5/QT_PROGRAMS_FULL/MDI_BT/MDI_BT/SUB_FT857/mainwindow_sub_ft857.h:17,
from /mnt/sde5/QT_PROGRAMS_FULL/MDI_BT/MDI_BT/SUB_FT857/mainwindow_sub_ft857.cpp:1:
/mnt/sde5/QT_PROGRAMS_FULL/MDI_BT/MDI_BT/SUB_FT857/mainwindow_sub_ft857.cpp: In member function ‘int MainWindow_SUB_FT857::Connect(QString)’:
/mnt/sde5/QT_PROGRAMS_FULL/MDI_BT/MDI_BT/SUB_FT857/mainwindow_sub_ft857.cpp:106:27: error: taking address of rvalue [-fpermissive]
106 | loc_addr.rc_bdaddr = *BDADDR_ANY;
| ^~~~~~~~~~actually there is another take on this error
" taking address of temporary value..."
( not sure why they differ )
loc\_addr.rc\_channel = (uint8\_t) 1; bind(s, (struct sockaddr \*)&loc\_addr, sizeof(loc\_addr)); // put socket into listening mode listen(s, 1); // accept one connection client = accept(s, (struct sockaddr \*)&rem\_addr, &opt); ba2str( &rem\_addr.rc\_bdaddr, buf ); fprintf(stderr, "accepted connection from %s\\n", buf); memset(buf, 0, sizeof(buf)); // read data from the client bytes\_read = read(client, buf, sizeof(buf)); if( bytes\_read > 0 ) { printf("received \[%s\]\\n", buf); }
Please any help to resolve this coding issue will be much appreciated.