0

How do the selection operators (#ifndef, #define, #endif) prevent header files from being included more than once within one fil

Wouldn't there be an error while compiling if the header files were called more than once in the same file? I'm confused regarding the purpose of these pre-processor directives.

6th Dec 2016, 3:08 PM
Krithika Ramesh
Krithika Ramesh - avatar
2 odpowiedzi
+ 2
You're right. There would be an error while compiling. And to prevent this errors you use headers guards, to make headers only include one time. Because if programs get bigger, you can't prevent using the include for a header file more than once. In the one file it's included and also maybe in another file
10th Dec 2016, 12:31 PM
lulugo
lulugo - avatar
+ 2
I mean if we have header-file A.h and B.h and in the main both are included and in A.h B.h is also included, B.h is included twice in the main and in A.h. And to prevent this header-guards are used
10th Dec 2016, 12:35 PM
lulugo
lulugo - avatar