r/C_Programming • u/Yuki_pop • 27d 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 • 27d ago
View all comments
Show parent comment
1
u/FedUp233 26d ago
As I said, it’s obviously theoretically possible, though I’m not sure why network mounts would make the problem any worse as far as having multiple paths to the same include file from within one compilation unit.
I can see however how a standardization body, which tries to get every corner case specified, would have problems agreeing on a perfect definition. I would think they might have just taken the UB route they took in many other places and said that in a case where the same file is included multiple times through multiple different paths, it’s UB. And just defined it for normal, not pathological cases.
I can certainly see an include having different paths in different compilation units, but that’s fine. If I was dealing with a code base that exhibited this problem, I think my first thought would be to fix it, but I’ve worked for a Marge company and I can see how management might just push it down the road and hope it never gets worse.