r/C_Programming • u/Yuki_pop • 27d ago
Could someone explain the practical differences between #pragma once and traditional include guards (#ifndef, #define, and #endif)?
84
Upvotes
r/C_Programming • u/Yuki_pop • 27d ago
View all comments
Show parent comment
2
u/not_a_novel_account 26d ago
Because they overlap. Team Tiger in Shanghai uses
#include <widget.h>and Team Dragon in Mumbai uses#include <component/widget.h>, both Dragon's and Tiger's headers are used by Team Eagle in Chicago. Each team builds, tests, and verifies their own code.The entire thing works because the build servers mount subcomponents into
/opt/BigCorp/<whatever>and set include flags to various places there. Different teams require subcomponents mounted in different places, and so downstream projects can have the same subcomponent mounted multiple times at different locations.When switching to
#pragma, suddenlywidget.his ambiguous. It's being accessed via different paths for the Team Tiger and Team Dragon code, and now Team Eagle is seeing definition collisions that they have no insight into.This is pretty much the exact arrangement that caused
#pragmato die during standardization. It's not a hypothetical. Major WG14 participants reported back on their experience with#pragmaand required this be solved. It couldn't be, so standardization died.