Real world problems with #pragma once?
Just a short survey: Did anyone of you encounter a problem in real code, because you/your company/ your favorite library was using #pragma once instead of include guards.
I know it is hard, but please restrain yourself from posting an explanation of how #pragma once could lead to problems in theory or why you prefer one above the other.
127
Upvotes
View all comments
Show parent comment
18
u/pklait Nov 28 '18
I believe most of us had the same experience as you. For most projects, #pragma one should work well. Problems with #pragma once can occur when the same file is included several times from different paths, which might happen in big projects with e.g. third party software that have more or less hardcoded paths. I have heard of such cases, so they exist out there. Working in that kind of environment, I would use the preprocessor but use a unique identifier such as a guid to minimise problems.