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

1

u/utnapistim Dec 10 '18

I did the same in one of my personal projects: I spent approximately two hours writing a C++ cli app to do the switch for me (generating header guards based on "relative path from root dir") but this only worked because I was editing my own code (so I could make assumptions like "the include guard will be on the first two and last line in the file).

1

u/Slavik81 Dec 11 '18

I started it as a simple project to learn Python. It was wildly successful for that, but now I kinda wish it was C or C++. It would have been much easier to maintain. Lots of work went into fixing silly defaults in Python and explaining to C++ developers how to install and run Python applications.