• 0 Posts
  • 1 Comment
Joined 1 year ago
cake
Cake day: June 13th, 2023

help-circle
  • Header guards and #pragma once serve the same purpose, so i’d say use whichever method you want. #pragma once should exist on most modern compilers. If your compiler doesn’t support that, then normal header guards.

    one advantage of #pragma once is that it reduces the pollution of #defines that header guards introduce. For every header file, there would be one #define FILE_NAME. Depending on your naming convention of these defines, it may clutter up the global namespace in the long run.

    Header guards, like you said, provide better compatibility. At the end of the day, use whichever you want. i use #pragma once because it’s much more convenient. I hope this answers your question!

    Edit: oh and of course, if the existing code base is using either one of those ways, stick to that same convention!