Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. macro usage error

macro usage error

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++tutorial
3 Posts 2 Posters 5 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    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.

    V L 2 Replies Last reply
    0
    • L Lost User

      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.

      V Offline
      V Offline
      Victor Nijegorodov
      wrote on last edited by
      #2

      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)

      1 Reply Last reply
      0
      • L Lost User

        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.

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        You are trying to dereference the BDADDR_ANY structure. You should just take the value, which is already the address.

        loc_addr.rc_bdaddr = BDADDR_ANY; // remove the asterisk.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups