Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

[C, C++] BlueZ Bluetooth BDADDR_ANY warning for address of temporary

Posted on 2012-03-17
3
Medium Priority
?
2,145 Views
Last Modified: 2013-12-14
I'm having some problems with g++ and the compiling process for a C/C++ program which use Bluetooth libraries under Ubuntu.

If i use gcc, it works fine with no warning; on the contrary, if i use g++ i get this warning:
warning: taking address of temporary
even if the program compiles fine and it works.

The involved lines reporting the error are:

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

Open in new window


In both the cases, BDADDR_ANY is involved.
How can i solve this warning?
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}})

Open in new window

0
Comment
Question by:ichigokurosaki
  • 2
3 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 2000 total points
ID: 37733027
Well, g++ is right - yet wrong as well. By using such a '#define'd struct, you are creating a temporary struct instance in all the statements above, thus passing a pointer to these functions. The point whre g++ is 'wrong' is simply that in these cases, this is an absolutely correct statement/operation and therefore the warning just does not matter - just ignore it.
0
 

Author Comment

by:ichigokurosaki
ID: 37733051
I solved it by using a variable to store the address. :)
0
 

Author Closing Comment

by:ichigokurosaki
ID: 37733058
jkr solution is fine, too!
i didn't see it before to close the question.

I want to assign the points to him.
0

Featured Post

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article we have discussed about the OS X EI Capitan and how to fix Wi-Fi issue in OS X El Capitan. We have explained how to delete system level preferences and create a new Wi-Fi location to resolve Wi-Fi issue.
DECT technology has become a popular standard for wireless voice communication. DECT devices are not likely to be affected by other electronic devices and signals because they operate in a separate frequency-band.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
Suggested Courses

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question