klog icon indicating copy to clipboard operation
klog copied to clipboard

Use a good discriminator in header guards

Open ikbenkous opened this issue 2 years ago • 1 comments

Include guard name collisions are no fun to debug. The core cpp guidelines recommend a 'good discriminator'. https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#sf8-use-include-guards-for-all-header-files

Since paths are unique, I recommend the following syntax: KLOG_PATH_TO_FILE_H

#define ... path
KLOG_DATABASE_H src/database.h
KLOG_WIDGETS_MAP_MAPWIDGET_H "src/widgets/map/mapwidget.h"

This way you won't have collisions of something like DATABASE_H between different projects or even inside of the project itself. There could be multiple database.h files...

Let me know what you think. @ea4k

ikbenkous avatar Sep 17 '23 22:09 ikbenkous

I was not aware of it. Very good catch. Thank you!

ea4k avatar Sep 23 '23 07:09 ea4k