CygLiDAR-ROS / cyglidar_d1

CygLiDAR D1 - ROS(SDK) Package (ROS1 / ROS2)
https://www.cygbot.com/
BSD 3-Clause "New" or "Revised" License
20 stars 25 forks source link

Fix compile warnings to get working with noetic, fixes #19 #20

Closed brawner closed 2 years ago

brawner commented 2 years ago

I found similar issues as discussed in here. https://github.com/CygLiDAR-ROS/cyglidar_d1/issues/19

This fixes the crash (at least for me) on ROS noetic and Ubuntu 20.04. I resolved ​a number of the compile warnings (not all) and on my system still lets me compile under c++11, but this works for me on c++14/17 as well.

I believe the culprit was that SIZE_MAX was redefined. SIZE_MAX is a constant already defined in stdint.h so I chose a different name for it here. Let me know if the name is not accurate to its usage.

Defining static variables in a header is generally discouraged. Every translation unit will have their own copies of those static variables and if they don't use them the compiler will warn about unused variables. Putting them into anonymous namespaces in the .cpp file where they are used allows their scope to be limited, while still preventing their export.

There were a couple of functions that didn't return a value though they were given a return type. Generally this isn't an issue, but I've run into problems before where the compiler over optimizes functions in that case

brawner commented 2 years ago

Looks like this resolves #16 and #19