r/C_Programming • • 27d ago

Could someone explain the practical differences between #pragma once and traditional include guards (#ifndef, #define, and #endif)?

84 Upvotes

58 comments sorted by

View all comments

Show parent comment

2

u/not_a_novel_account 26d ago

why network mounts would make the problem any worse as far as having multiple paths to the same include file from within one compilation unit.

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, suddenly widget.h is 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 #pragma to die during standardization. It's not a hypothetical. Major WG14 participants reported back on their experience with #pragma and required this be solved. It couldn't be, so standardization died.

1

u/FedUp233 26d ago

That makes sense. But I think I’d put this in the poor team leadership/management bucket. Someone in charge of the whole project should set standards for things like this and tell the teams “this is how it will be done” after getting input from both teams on why they chose a particular method. It the job of management and technical leads to make sure this type of stuff doesn’t happen!