4 ms·
It seems to me that all this fuss over multiple includes and include guards would be solved by something like a #stop directive: #ifdef STDIO_H #stop #en
by rootbear 12y ago
It seems to me that all this fuss over multiple includes and include guards would be solved by something like a #stop directive:
#ifdef STDIO_H
#stop
#endif
#define STDIO_H
which would cause the preprocessor to skip the rest of the file. How would this not be a better solution? What am I missing?
- RegW 12y agoIt would be faster, but this would still cause the compiler to open and start parsing the file unnecessarily (possibly multiple times from multiple included files). Another approach would be to have a pragma that means: "just don't bother including this file again if you see it", and have the compiler remember it. Perhaps there is - its a long time since I programmed in C.
- clarry 12y agoIf the compiler can remember there's a pragma like that, then it can also remember there's an include guard wrapping the file.
- tbirdz 12y agoThere is #pragma once It's not standard, but it is supported by many compilers.
- rootbear 12y agoGood point. Opening a file has non-trivial cost, so perhaps the added cost of burdening the compiler with avoiding needless includes is worth it. As a long time C hacker I hate to say this, but I guess the whole include mechanism is a bad design or, perhaps, a design that didn't scale well.