C/C++ 警告:带有 BDADDR_ANY 蓝牙库的临时地址 [英] C/C++ Warning: address of temporary with BDADDR_ANY Bluetooth library

查看:21
本文介绍了C/C++ 警告:带有 BDADDR_ANY 蓝牙库的临时地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 g++ 和在 Ubuntu 下使用蓝牙库的 C/C++ 程序的编译过程中遇到了一些问题.

I'm having some problems with g++ and the compiling process for a C/C++ program which use Bluetooth libraries under Ubuntu.

如果我使用 gcc,它可以正常工作,没有警告;相反,如果我使用 g++,我会收到此警告:

If i use gcc, it works fine with no warning; on the contrary, if i use g++ i get this warning:

警告:取临时地址

即使程序编译正常并且可以运行.

even if the program compiles fine and it works.

报告错误的相关行是:

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

在这两种情况下,都涉及 BDADDR_ANY.

In both the cases, BDADDR_ANY is involved.

我该如何解决这个警告?

How can i solve this warning?

BDADDR_ANY 在 bluetooth.h 中定义如下:

BDADDR_ANY is defined in bluetooth.h like:

/* BD Address */
typedef struct {
    uint8_t b[6];
} __attribute__((packed)) bdaddr_t;

#define BDADDR_ANY   (&(bdaddr_t) {{0, 0, 0, 0, 0, 0}})

推荐答案

(&(bdaddr_t) {{0, 0, 0, 0, 0, 0}})

构造一个临时对象并使用它的地址.这在 C++ 中是不允许的.

Constructs a temporary object and uses its address. This isn't allowed in C++.

您可以通过创建一个命名的临时变量并在其上使用 bacpybacmp 来解决此问题:

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

bdaddr_t tmp = { };

bacpy(&result[mote++], &tmp);

while (bacmp(bdaddr, &tmp)) {
    //
}

这篇关于C/C++ 警告:带有 BDADDR_ANY 蓝牙库的临时地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆