If I understand correctly, you want to know if, in the absence of security guards, he can include the header file several times, causing an error or dangerous behavior. This is after excluding several definitions, etc.
Imagine a malicious programmer with no security devices in the header file. Its header file defines one macro, SZ , which is the size you use for your statically distributed arrays. The programmer could write his header file as follows:
#ifndef SZ #define SZ 1024 #else #if SZ == 1024 #undef SZ #define SZ 128 #else #error "You can include me no more than two times!" #endif #endif
Now, if you include the header file once, you get SZ equal to 1024. If you include it twice, SZ will be 128. Of course, most real-world programmers are not malicious, and no one actually writes the code as described above.
Note that the C standard allows assert.h be #include d more than once with different behaviors, depending on whether NDEBUG defined when NDEBUG is included. Therefore, assert.h cannot include protection. This is a function, not an error.
Alok singhal
source share