This is because it is not only regular, but also mandatory in C:
#include <something.h>
Although it is rarely used in Delphi. And when it is used, it really used to configure these {$DEFINE} :
{$INCLUDE 'something.inc'}
This matters because DEFINES are only valid when compiling a single object (it can be a .PAS file or a .C file). Delphi uses the uses to include other units, and C uses include to include headers. In C headers may include other headers. The pattern you are asking for is used to prevent recursive re-inclusion of the same header.
To make the matrices crystal clear, here is an example of what can be used in C, and the equivalent in Delphi. Let's say we have 3 files setup, where A must include both B and C , and B needs to include C C files look like this:
// ----------------------- Ah #ifndef A #define A #include "Bh" #include "Ch" // Stuff that goes in A #endif // ------------------------ Bh #ifndef B #define B #include "Ch" // Stuff that goes in B #endif // ----------------------- Ch #ifndef C #define C // Stuff that goes in C #endif
Without defining the conditions in Ch file Ch will eventually be included twice in Ah . So the code in Delphi will look:
The Delphi / Pascal version should not protect "C" from being included twice in "A", because it does not use {$INCLUDE} to achieve this, it uses the uses statement. The compiler will get exported characters from the B.dcu and C.dcu without the risk of including characters from C.dcu twice.
Other reasons to see more precompiler commands in C code:
- The precompiler is much more powerful than Delphi. A
{$DEFINE} in Delphi code deals only with conditional compilation, and variant C can be used both for conditional compilation and as a replacement for words. - Mandatory use of
#include for headers means that you can have a header that defines macros. Or you may have a header configured by specifying some #define before the actual #include <header.h>
source share