O'Reilly logo

Just Enough C/C++ Programming by Guy W. Lecky-Thompson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Avoiding Multiple Includes

One useful way to apply the #define directive is as a mechanism for avoiding multiple includes. Compilers deal with including the same header file in different ways. To ensure compatibility, it’s good practice to keep these cases from actually occurring in the first place.

The worst case is when a compiler cannot compile a project because it has several (albeit identical) definitions for the same constant or multiple identical function prototypes. More advanced compilers might be able to resolve these, but the most common approach is simply to prevent compilation.

When programming, this can be inconvenient, so it is better just to prevent it from happening at all by avoiding including the same header file twice. The ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required