Solved

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

Posted on 2012-03-17
3
1,794 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 500 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
This article is a step by step guide on how to create a basic PTP link using Ubiquiti airOS devices. This guide can be used on the following Ubiquiti AirMAX devices. Nanostation, Bullets, AirBridge, Nanobeam, NanoBridge to name a few. Please review …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

830 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