Compatibility with non-GNU compilers

本文探讨了GCC中__attribute__机制的设计精妙之处及其在不同平台上的灵活使用方法。作者详细解释了如何通过预处理器定义使其在非GNU编译器环境中被忽略,并展示了这一机制在函数声明中的具体应用实例。

Fortunately, the __attribute__ mechanism was cleverly designed in a way to make it easy to quietly eliminate them if used on platforms other than GNU C. Superficially, __attribute__ appears to have multiple parameters (which would typically rule out using a macro), but the two sets of parentheses effectively make it a single parameter, and in practice this works very nicely.

/* If we're not using GNU C, elide __attribute__ */
#ifndef __GNUC__
#  define  __attribute__(x)  /*NOTHING*/
#endif

Note that __attribute__ applies to function declarations, not definitions, and we're not sure why this is. So when defining a function that merits this treatment, an extra declaration must be used (in the same file):

/* function declaration */
void die(const char *format, ...) __attribute__((noreturn))
                                  __attribute__((format(printf,1,2)));

void die(const char *format, ...)
{
	/* function definition */
}
atkin_make Base path: /home/robot/demo01_ws Source space: /home/robot/demo01_ws/src Build space: /home/robot/demo01_ws/build Devel space: /home/robot/demo01_ws/devel Install space: /home/robot/demo01_ws/install #### #### Running command: "cmake /home/robot/demo01_ws/src -DCATKIN_DEVEL_PREFIX=/home/robot/demo01_ws/devel -DCMAKE_INSTALL_PREFIX=/home/robot/demo01_ws/install -G Unix Makefiles" in "/home/robot/demo01_ws/build" #### -- The C compiler identification is GNU 9.4.0 -- The CXX compiler identification is GNU 9.4.0 -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working C compiler: /usr/bin/cc - skipped -- Detecting C compile features -- Detecting C compile features - done -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Check for working CXX compiler: /usr/bin/c++ - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done -- Using CATKIN_DEVEL_PREFIX: /home/robot/demo01_ws/devel -- Using CMAKE_PREFIX_PATH: /home/robot/demo01_ws/devel/.private/catkin_tools_prebuild;/home/robot/UR5-Pick-and-Place-Simulation-main/catkin_ws/devel;/opt/ros/noetic -- This workspace overlays: /home/robot/UR5-Pick-and-Place-Simulation-main/catkin_ws/devel;/opt/ros/noetic -- Found PythonInterp: /usr/bin/python3 (found suitable version "3.8.10", minimum required is "3") -- Using PYTHON_EXECUTABLE: /usr/bin/python3 -- Using Debian Python package layout -- Found PY_em: /usr/lib/python3/dist-packages/em.py -- Using empy: /usr/lib/python3/dist-packages/em.py -- Using CATKIN_ENABLE_TESTING: ON -- Call enable_testing() -- Using CATKIN_TEST_RESULTS_DIR: /home/robot/demo01_ws/build/test_results -- Forcing gtest/gmock from source, though one was otherwise available. -- Found gtest sources under '/usr/src/googletest': gtests will be built -- Found gmock sources under '/usr/src/googletest': gmock will be built CMake Deprecation Warning at /usr/src/googletest/CMakeLists.txt:4 (cmake_minimum_required): Compatibility with CMake < 2.8.12 will be removed from a future version of CMake. Update the VERSION argument <min> value or use a ...<max> suffix to tell CMake that the project does not need compatibility with older versions. CMake Deprecation Warning at /usr/src/googletest/googlemock/CMakeLists.txt:45 (cmake_minimum_required): Compatibility with CMake < 2.8.12 will be removed from a future version of CMake. Update the VERSION argument <min> value or use a ...<max> suffix to tell CMake that the project does not need compatibility with older versions. CMake Deprecation Warning at /usr/src/googletest/googletest/CMakeLists.txt:56 (cmake_minimum_required): Compatibility with CMake < 2.8.12 will be removed from a future version of CMake. Update the VERSION argument <min> value or use a ...<max> suffix to tell CMake that the project does not need compatibility with older versions. -- Found PythonInterp: /usr/bin/python3 (found version "3.8.10") -- Found Threads: TRUE -- Using Python nosetests: /usr/bin/nosetests3 -- catkin 0.8.12 -- BUILD_SHARED_LIBS is on -- BUILD_SHARED_LIBS is on WARNING: Package name "levelManager" does not follow the naming conventions. It should start with a lower case letter and only contain lower case letters, digits, underscores, and dashes. WARNING: Package name "robotName_description" does not follow the naming conventions. It should start with a lower case letter and only contain lower case letters, digits, underscores, and dashes. -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- ~~ traversing 37 packages in topological order: -- ~~ - robotiq (metapackage) -- ~~ - robotiq_2f_140_gripper_visualization -- ~~ - robotiq_2f_85_gripper_visualization -- ~~ - robotiq_2f_c2_gripper_visualization -- ~~ - robotiq_3f_gripper_articulated_gazebo -- ~~ - robotiq_3f_gripper_articulated_msgs -- ~~ - universal_robots (metapackage) -- ~~ - ur_msgs (plain cmake) -- ~~ - plumbing_param_server -- ~~ - plumbing_pub_sub -- ~~ - plumbing_server_client -- ~~ - plumbing_test -- ~~ - robotiq_ethercat -- ~~ - robotiq_2f_gripper_control -- ~~ - robotiq_ft_sensor -- ~~ - robotiq_modbus_rtu -- ~~ - robotiq_modbus_tcp -- ~~ - robotiq_2f_140_gripper_gazebo -- ~~ - robotiq_2f_85_gripper_gazebo -- ~~ - robotiq_2f_gripper_action_server -- ~~ - robotiq_3f_gripper_control -- ~~ - rosbag_demo -- ~~ - robotiq_3f_gripper_joint_state_publisher -- ~~ - tf01_static -- ~~ - tf03_tfs -- ~~ - tf02_dynamic -- ~~ - tf04_test -- ~~ - ur5_moveit_config -- ~~ - ur_description -- ~~ - ur_gazebo -- ~~ - robotiq_3f_gripper_articulated_gazebo_plugins -- ~~ - robotiq_3f_gripper_visualization -- ~~ - robotiq_3f_rviz -- ~~ - ur_kinematics -- ~~ - nav_demo -- ~~ - urdf01_rviz -- ~~ - urdf02_gazebo -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ CMake Error at /opt/ros/noetic/share/catkin/cmake/catkin_workspace.cmake:100 (message): This workspace contains non-catkin packages in it, and catkin cannot build a non-homogeneous workspace without isolation. Try the 'catkin_make_isolated' command instead. Call Stack (most recent call first): CMakeLists.txt:69 (catkin_workspace) -- Configuring incomplete, errors occurred! See also "/home/robot/demo01_ws/build/CMakeFiles/CMakeOutput.log". See also "/home/robot/demo01_ws/build/CMakeFiles/CMakeError.log". Invoking "cmake" failed
最新发布
11-21
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值