gioblu / PJON

PJON (Padded Jittering Operative Network) is an experimental, arduino-compatible, multi-master, multi-media network protocol.
Other
2.73k stars 239 forks source link

Prevent linking errors: Inline LINUX_Interface functions and remove global vars #389

Closed rainerschoe closed 3 years ago

rainerschoe commented 3 years ago

This prevents linking errors if PJON is included in multiple compilation units. Also using the static singleton pattern is safer than global vars, especially with multiple compilation units.

Currently projects cannot be linked if PJON.h is included in more than one cpp file, as global vars and function definitions will be there multiple times and cause conflicts.

One solution would be to separate function declarations and definitions into .h[pp] and .cpp files, however in your project you do not seem to use cpp files at all and also do not have a build system set up. So to fix this I just used inlining and the static singleton pattern (for global vars). This will effectively prevent linking errors (might cause some codesize increase).

gioblu commented 3 years ago

Thank you very much, that looks a sane solution, I will test it and report back.

gioblu commented 3 years ago

All looks fine @rainerschoe , this is effectively much better, as you correctly stated. Feel free to open a pull-request for the higher level class you wish to contribute. Thank you very much.