Ask Your Question
0

Why doesn't ROS_INFO allow calling std::queue.size() inside as a param

asked 2016-04-27 20:16:38 -0500

janindu gravatar image

I have declared a global variable queue

// Global variable for queue declaration
std::queue<geometry_msgs::PointStamped::ConstPtr> waypointQueue;

And I have subscribed to a topic. Here is my subscriber callback method.

/*
* Callback method to be executed on reception of a message
*/
void clickedPointsCb(const geometry_msgs::PointStamped::ConstPtr& msg) {
  ROS_INFO("%f %f %f", msg->point.x, msg->point.y, msg->point.z);
  waypointQueue.push(msg);
  ROS_INFO("%d", waypointQueue.size());
}

When I try to build this, I get the following error.

In file included from /opt/ros/indigo/include/ros/ros.h:40:0,
                 from /home/janindu/workspace/catkin_ws/src/turtlebot_waypoint_navigation/src/turtlebot_waypoint_navigation_v2.cpp:10:
/home/janindu/workspace/catkin_ws/src/turtlebot_waypoint_navigation/src/turtlebot_waypoint_navigation_v2.cpp: In function ‘void clickedPointsCb(const ConstPtr&)’:
/opt/ros/indigo/include/ros/console.h:342:176: warning: format ‘%d’ expects argument of type ‘int’, but argument 8 has type ‘std::queue<int>::size_type {aka long unsigned int}’ [-Wformat=]
     ::ros::console::print(filter, __rosconsole_define_location__loc.logger_, __rosconsole_define_location__loc.level_, __FILE__, __LINE__, __ROSCONSOLE_FUNCTION__, __VA_ARGS__)
                                                                                                                                                                                ^
/opt/ros/indigo/include/ros/console.h:345:5: note: in expansion of macro ‘ROSCONSOLE_PRINT_AT_LOCATION_WITH_FILTER’
     ROSCONSOLE_PRINT_AT_LOCATION_WITH_FILTER(0, __VA_ARGS__)
     ^
/opt/ros/indigo/include/ros/console.h:375:7: note: in expansion of macro ‘ROSCONSOLE_PRINT_AT_LOCATION’
       ROSCONSOLE_PRINT_AT_LOCATION(__VA_ARGS__); \
       ^
/opt/ros/indigo/include/ros/console.h:557:35: note: in expansion of macro ‘ROS_LOG_COND’
 #define ROS_LOG(level, name, ...) ROS_LOG_COND(true, level, name, __VA_ARGS__)
                                   ^
/opt/ros/indigo/include/rosconsole/macros_generated.h:110:23: note: in expansion of macro ‘ROS_LOG’
 #define ROS_INFO(...) ROS_LOG(::ros::console::levels::Info, ROSCONSOLE_DEFAULT_NAME, __VA_ARGS__)
                       ^
/home/janindu/workspace/catkin_ws/src/turtlebot_waypoint_navigation/src/turtlebot_waypoint_navigation_v2.cpp:58:3: note: in expansion of macro ‘ROS_INFO’
   ROS_INFO("%d", q.size());

However, if I modify the subscriber callback method as follows, it compiles and runs just fine.

/*
* Callback method to be executed on reception of a message
*/
void clickedPointsCb(const geometry_msgs::PointStamped::ConstPtr& msg) {
  ROS_INFO("%f %f %f", msg->point.x, msg->point.y, msg->point.z);
  waypointQueue.push(msg);
  int i = waypointQueue.size();
  ROS_INFO("%d", i);
}

Am I missing something?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2016-04-27 21:12:21 -0500

ahendrix gravatar image

This looks like just a warning; it shouldn't prevent your code from compiling and running.

The warning in question is telling you that you're asking it to print an unsigned type with a signed format string:

warning: format ‘%d’ expects argument of type ‘int’, but argument 8 has type ‘std::queue<int>::size_type {aka long unsigned int}’

Instead of using the %d type specifier, you should use an unsigned specifier like %ud, or the dedicated specifier for size_t: %zd

edit flag offensive delete link more

Comments

Thanks! Worked with %zd Note - Still warns for %ud

janindu gravatar imagejanindu ( 2016-04-27 22:58:17 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2016-04-27 20:16:38 -0500

Seen: 1,340 times

Last updated: Apr 27 '16