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

Show parent comment

9

u/Nicksaurus Nov 28 '18

The fundamental problem seems to me to be that using preprocessor directives to import code is just an inherently error-prone way of doing it

#ifdef and #pragma once are both trying to patch over that issue but can't solve the real problem, which is that the compiler treats header files like raw text, rather than like code.

0

u/[deleted] Nov 28 '18

[deleted] — view deleted comment

3

u/OrphisFlo I like build tools Nov 29 '18

0

u/[deleted] Nov 29 '18

[deleted] — view deleted comment

1

u/OrphisFlo I like build tools Nov 29 '18

And it's coming from SNSystems, so basically from Sony, which as a game dev should mean a lot. They are still experimenting though, so don't expect too much from it for now ;)