1

Many C++ programmers use

#ifndef _SOME_TAG_
#define _SOME_TAG_

//Code here...

#endif // _SOME_TAG_

to avoid including the same file more than once.

Why isn't this the default behavior for compilers? I see now that there are cases where you'd want to include the same file more than once, but why not make including the file only once the default? This would save people the time to write all the clauses with different names.

  • "Why isn't.." questions are rarely good (the second question is better, but a duplicate). But this comes from *way back* - from the era when the CPP was separate from even C itself and the whole system was extremely "dumb". C++ inherited a lot of baggage, for better or worse. – user2864740 Aug 28 '14 at 20:48
  • See also http://stackoverflow.com/questions/24943620/when-is-it-useful-to-include-the-same-header-multiple-times-in-one-file – Mark Ransom Aug 28 '14 at 20:50
  • @user2864740 I don't know if I agree with that assertion, this recent question: [Why is assert a macro and not a function?](http://stackoverflow.com/questions/25285557/why-is-assert-a-macro-and-not-a-function) could easily have been an why isn't question and would still have been good. – Shafik Yaghmour Aug 28 '14 at 20:50
  • @ShafikYaghmour Fair enough: "rarely good". – user2864740 Aug 28 '14 at 20:50

0 Answers0