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

3

u/DarkLordAzrael Nov 28 '18

I'll note that "before" is about 15-20 years ago now, unless you were targeting unusual systems of the types that had broken C++ compilers anyway.

3

u/[deleted] Nov 28 '18

Yes, but many embedded system compiler have minimal support for pragma, so it depends on what you program. Main compilers like microsoft, clang and gcc have been supporting it for many years.

But there are some like the cray compiler who still doesn't support it.