If you open the file to read the contents (you can even right click the include directive in most editors to open the file), you will see that include files usually start with something like:
#ifndef _WINDOWS_
#define _WINDOWS_
...
So the first time it will go in the file since _WINDOWS_
is not defined, therefore it will be defined and the contents of the file will be included. The second time the #ifndef
will fail since the define was done previously.
This is the standard way to put a safeguard. Aanother way, which is supported by many compilers, is to use #pragma once
. This has the advantage of preventing collisions even if someone defines the same constant in another header file.