r/C_Programming • • 25d ago

Could someone explain the practical differences between #pragma once and traditional include guards (#ifndef, #define, and #endif)?

81 Upvotes

58 comments sorted by

View all comments

Show parent comment

1

u/ComradeGibbon 24d ago

Background in in embedded work is very common to have one code base that targets several to sometimes dozens of targets. Where you may have lots of modules that are part of the code tree but are not and cannot be built.

1

u/FedUp233 23d ago

Isn’t that what make, cmake, or whatever build system you are using is supposed to take care of depending on what target you tell it to build?

I’ve worked on large systems that had multiple targets and we never had an issue with trying to build stuff for a target that was not meant for that target. A combination of the make files and conditional compilation was maintained to take care of that.

Sorry, but a decently designed system should never get to the point of pulling in a file that was not meant for the build (as far as C and C++ or whatever source files) and for header file normal preprocessor directives should handle it fine.

Just my opinion of course.