r/C_Programming • u/Yuki_pop • 23d ago
Could someone explain the practical differences between #pragma once and traditional include guards (#ifndef, #define, and #endif)?
81
Upvotes
r/C_Programming • u/Yuki_pop • 23d ago
View all comments
Show parent comment
24
u/Maxwelldoggums 23d ago
I work professionally on a problematically large C++ project with terrible practices. Some of our headers are 10k+ lines of code, and include dozens of other headers. We actually achieved noticeably faster compile-times using ‘#pragma once’ for the reasons you outlined. Using a traditional include guard required the compiler to scan through the entire text of the header to find a matching ‘#endif’, while it can safely early-out on a pragma.