Why is #pragma once a weaker guarantee against double inclusion than a traditional include guard?
Correct answer
C. It is non-standard, so a compiler may ignore it and reprocess the header
20 views
C. It is non-standard, so a compiler may ignore it and reprocess the header
20 views
#pragma once is a widely supported extension rather than a feature of the C standard, so a conforming compiler may ignore the directive and include the file again. A guard built from #ifndef, #define and #endif relies only on macro semantics and is fully portable. Both mechanisms work per translation unit, which is why neither prevents the same header from being included in two different source files.
Asked in: NTS, PPSC IT, Campus Interviews
Not sure why the answer is C? Ask here and get an explanation.