r/C_Programming • u/Yuki_pop • 25d ago
Could someone explain the practical differences between #pragma once and traditional include guards (#ifndef, #define, and #endif)?
81
Upvotes
r/C_Programming • u/Yuki_pop • 25d ago
View all comments
Show parent comment
2
u/FedUp233 24d ago
I would think you’d want something like #error so that you’d know the build was picking up a file that was not supposed to be included in it and you could go fix the problem in make or whatever build system you were using.
Having things just disappear silently seems like a really bad idea!
Plus, then what happens at the link step when it tries to link with object files that are just not there? Or if used in a header, what about the part of the file before it hit the directive? That’s already processed and could well leave the preprocessor or compiler in an invalid state to just stop? Does it just abandon the rest of the file being included? What about #if directives that have not been closed?