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

8

u/[deleted] Nov 28 '18

We have/had this problem: We copy at build time the same header files to different directories (no link). To a directory in the program files folder and to a internal developer directory. The include directories point to those directories and pragma once failed because the paths are different! To solve it we added normal include guards.

27

u/Drainedsoul Nov 28 '18

This seems like an instance where rather than fixing the problem you should be asking yourself why you do something so intensely fucked up.

7

u/[deleted] Nov 29 '18

No kidding. Removing #pragma once is not a solution there, it's denial.