I have a source code structured as follows
foo.h (header from c library)
#pragma once
struct foo {...};
bar.h
#pragma once
extern "C" {
#include "foo.h"
}
class Bar {
foo val;
...
};
bar.cpp
// some Bar methods implementation
user.cpp
#include "bar.h"
...
extern "C" {
#include "foo.h"
}
...
/* some additional foo usage */
What I expect to happen is that if foo.h included multiple times, #pragma once shall make it so it's included first time only. But what happens is that in bar.h it is not included at all, and include works in user.cpp only. So preprocessor output of user.cpp.i looks somewhat like that:
extern "C" {/* nothing is here, literally empty braces */}
class Bar {
foo val;
...
};
extern "C" {/*actual header content*/}
...
/*the rest of user.cpp content*/
I'd expect foo.h pasted at very first include, but what happens is that struct foo is undefined in bar.h but defined in user.cpp.
I can solve the issue for now by reordering the includes, but why might that happen at all?
UPDATE:
And rearranging includes does nothing. Since bar.cpp still gets no include added by preprocessor.