What are compiler "multiple include guards" ?

While checking if correct header file was in use I added #ifdef #pragma ... #endif preprocessor directives. The pragma message I was expecting in compiler output was not there.

So I just added #pragma message without the #ifdef ...#endif block and got multiple messages in compiler output.

Does that meas the entire header file was somehow (partially) included in source code multiple times?

Does that indicates that the standard #ifndef #define ...#endif preprocessor directives included in EVERY header file is also ignored?

And this " multiple include guards" stops the compiler to see multiple definitions?

Here is partial compiler output

/home/jim/.arduino15/packages/arduino/hardware/sam/1.6.8/cores/arduino/Print.h
Multiple include guards may be useful for:

Just asking. Jim

Does that meas the entire header file was somehow (partially) included in source code multiple times?

What exactly are you compiling? When you "verify" a sketch, the IDE builds 20+ files, each of which may include Print.h once. I don't see any reason to suspect that the guards aren't working.

BTW, if you generate preprocessor output with "-E", you can look at it and see which definitions were sucked in from which code, which may or may not be easier than figuring out the output of the option you are using...

westfw:
What exactly are you compiling? When you “verify” a sketch, the IDE builds 20+ files, each of which may include Print.h once. I don’t see any reason to suspect that the guards aren’t working.

BTW, if you generate preprocessor output with “-E”, you can look at it and see which definitions were sucked in from which code, which may or may not be easier than figuring out the output of the option you are using…

It should not matter WHAT I am compiling , but since it appears important for the discussion , here is my test code:

#define PRAGMA_INCLUDE
#define PRAGMA_PRINT

#include <Print.h> 
//#pragma message HERE
//#error STOP ***********************************************
void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}

" I don’t see any reason to suspect that the guards aren’t working. "

So how do you explain the pragma messages within MY #ifdef#endif did not show up?
Are these guards ONLY for header #define flags ?

That is what I am asking.

And respectfully disagree - the header with #ifndef #define#endif SHOULD be included in source only once to prevent multiple definitions.

That seems to be sort-off after thought with this “multiple include guards”.

And I did not say they are not working.

I should see at least one expected pragma output, but I did not.

" the IDE builds 20+ files "
even that should have produced SOME pragma outputs, it did not.

This is the traditional way that will work with any compiler, i.e., it does not depend on pragmas: http://c-faq.com/cpp/nestincl.html

#include <Print.h>

Have you created a file named Print.h that you are trying to include in your sketch?

Um, are you trying to use Microsoft pragmas with gcc ? I can't find any gcc references to PRAGMA_PRINT or PRAGMA_INCLUDE, for example... All of your posts seem to be a bit short on information; I can't figure out what you're thing to do, or what the results have actually been...

Creating an additional Print.h would be bad, since there is an existing Print.h as part of the core, and the arduino include paths are a bit convoluted.

No, just including “system” Print.h up front, before Setup, so I can verify if it is the correct file I have modified for printf function.
I just learned that IDE builds arduino15 directory and I have to modify Print.h in that directory structure.

The instructions on how to modify Print.h neglect to mention that source code in arduino15 directory structure needs to be modified.
That is all I am after, and I have accomplished that after few detours.

FYI #pragma is not limited to MS and was not the subject of this post.

The subject was “multiple include guards” and the code presented to generate this message should be sufficient to discuss that.

Time to google it.

Stand by.

Language defines "include guard " as this standard sequence of preprocessor directives:

#ifndef GUARD
#define GUARD

… guarded code here

#endif

Same can be accomplished by using non- standard

#pragma once

The preprocessor option -H scans the entire list / tree of #includes e/w these include guards and lists them in tree sequence .

Therefore the compiler output shows tree like LISTS of includes and than compiled code using these guards.
Two distinct functions.

Little hard to scroll thru the output to identify these parts.

Problem resolved.

Jim

For a long time gcc disdained #pragmas. If you included any #prgamas it would launch into a game.