-7

It's laborious to put an include guard in every header file. Most other language don't need it anyway. Python doesn't have 'import' guard.

Hanhan Li
  • 455
  • 5
  • 13
  • 5
    Most modern compilers have `#pragma once`. Put this at the beginning of your header files and no more need to put an include guard. – Jabberwocky Aug 07 '15 at 06:13
  • 1
    possible duplicate of [Why aren't include guards in c++ the default?](http://stackoverflow.com/questions/27260752/why-arent-include-guards-in-c-the-default) – m.s. Aug 07 '15 at 06:16
  • Without any hints the preprocessor can't distinguish header files from regular translation units. – πάντα ῥεῖ Aug 07 '15 at 06:17
  • 1
    Feel free to join the ISO committee and put forward your idea :-) That is, after all, how changes are made to the language. – paxdiablo Aug 07 '15 at 06:21
  • 1
    @πάνταῥεῖ: There are many arguments pro and contra, but I'm sure it is not too hard to make the preprocessor file-aware, so this one is bogus, IMO. – Rudy Velthuis Aug 07 '15 at 06:26
  • @RudyVelthuis What do you mean _file aware_? How? Based on filename extension? That won't work. – πάντα ῥεῖ Aug 07 '15 at 06:29
  • File-aware: aware of the fact that a file is included, header or not. And yes, preprocessors could probably even detect different kind of files. If you say: this is for historical reasons, fine. If you say: because it is impossible, then I don't believe it. – Rudy Velthuis Aug 07 '15 at 06:32
  • @RudyVelthuis - specifying how to decide if an include file is unique on arbitrary file systems **IS** hard. – Bo Persson Aug 07 '15 at 07:49
  • If it is so hard, then why can other languages, also on many different file systems, cope with it? I assume that on any of those, files have unique names. – Rudy Velthuis Aug 07 '15 at 07:52
  • FWIW, I am not advocating a change. But saying: "it is/was not possible" is a bogus argument, IMO. – Rudy Velthuis Aug 07 '15 at 08:01
  • Detecting the "unique" pathname of an included file is probably impossible. Directories can be accessed via many paths (links, symbolic links) and then when you throw in network paths and share names the problem becomes impossible. If the same header file is accessible by 2 or more paths which is the "real" one? – Richard Critten Aug 07 '15 at 08:23
  • @m.s. Oh yeah, it was a duplicate question. – Hanhan Li Aug 07 '15 at 20:41

1 Answers1

4

C/C++ including is a textual thing. It can be used multiple times successfully.

#define STUFF  EXPANSION1
#include "mydataset.h"

#undef  STUFF 
#define STUFF EXPANSION2
#include "mydataset.h"

Allows a macro data set to be filled out with differing behavior.

mksteve
  • 12,614
  • 3
  • 28
  • 50