Vex header file wrappers

Is there any particular reason why the vex header files such as robot-config.h and vex.h don’t include #ifndef to protect from multiple definitions?

There’s no particular reason other than they are probably not needed in most situations. I get the feeling that header guards are not well understood. First, they only impact the compiler pre-processor, they stop an include file being processed several times when being included from other include files. For example, stdio.h is often included in other header files, there’s no reason for the pre-processor or compiler to have to deal with it more than once for any given C or C++ file that uses it, so it’s appropriate for it to use header guards. However, it’s unlikely that vex.h will be included more than once in a given C++ file, if it is for some reason, the files that it includes all have header guards so it generally will not matter.

Header guards do not help across different C++ source files. If bar.cpp and foo.cpp both include vex.h, it will be processed for both no matter if header guards are used or not, the pre-processor and compile process starts over for each one.

6 Likes