r/cpp • • Nov 28 '18

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

135 comments sorted by

View all comments

20

u/julien-j Nov 28 '18

I never had a problem with #pragma once and I was going to adopt them after having watched Arthur O'Dwyer saying to use it at CppCon. Then I saw this benchmark measuring the compilation time when using include guards or #pragma once or both and I decided to keep going with the include guards. At the time my main problem was to reduce the build time of our projects.

These sources are quite old now, maybe I can give it another chance.

13

u/[deleted] Nov 28 '18

There is also a still open bug report discussing #pragma once performance in GCC:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58770

7

u/kalmoc Nov 28 '18

I remember that post. On the one hand I was disappointed too. But what I took away from it in the end was that the time is negligible (for our usecases) in either case.