Why does ROS use macros for logs?
This is purely an academic question, to sate my curiosity.
What were the advantages gained by using macros as the logging interface for C++, and not some ros::logError() function? Is there a reason this approach was chosen? As I understand, most people in the C++ community hate macros with a passion, so it seems odd to see them used for something that seems trivially accomplished through other means.
Thanks!
I don't know for sure, but I guess the fact that fi the various
THROTTLE
versions insert a static variable at the site of invocation, and access to__LINE__
and__FILE__
constants in all of them have something to do with it.Interesting observation! And since __LINE__ and __FILE__ are read by the preprocessor, something like an inline function wouldn't be able to use them.
Maybe there is a workaround, but I guess that would be line and file of the inline function and not the caller.