On 13 January 2011 16:59, Achilleas Margaritis wrote: >>> >>> The pragma can be ignored by other compilers. Conditional compilation >>> would help in including the header for other compilers. >> >> Except the header wouldn't exist if you use other compilers, because >> you need gcc to generate it. > > No, in other compilers you would have to provide the header manually. > > The idea is this: if you use gcc, the headers may be generated for > you. If you don't use gcc, then you have to create the headers > yourself. > >>> The declaration would be entangled with the definition, and the tool >>> would have to untangle them. It doesn't sound so easy to me. >>> >>> An external tool would have to duplicate a lot of code from GCC, and >>> it would possibly not get the result 100% correct, given the >>> complexity of the language. >> >> GCC would not get it 100% either, you'd be better using a stricter >> parser such as EDG. > > Why not? doesn't GCC contain all that is required for that parsing to succeed?
GCC has bugs and doesn't parse everything 100% correctly, given the complexity of the language. >>> If foo.cpp does not include foo.hpp, then the definitions in foo.cpp >>> would not be recognized by the compiler. >> >> Eh? >> Your OP said foo.cpp looked like: >> >> file foo.cpp: >> >> #include <list> >> >> class Foo { >> public: >> void bar() { >> } >> }; >> >> std::list<Foo *> foos; >> >> static int data = 0; >> >> So it doesn't include foo.hpp and doesn't need to. My point was that your foo.cpp doesn't have an #include (or #autoinclude) for foo.hpp, and doesn't need one either. foo.cpp contains all the necessary declarations already - it MUST do, or you couldn't generate foo.hpp! So there's no need for foo.cpp to include foo.hpp (and doing so would require the compiler to handle duplicate class definitions, which is more implementation work, for no good reason.) > Can the GCC linker find the symbol Foo::bar() in the above code? > > I did a test (with mingw), and the result is that if I don't define > Foo::bar() outside the class, then the linker doesn't find the > function. > > The same thing happens with Microsoft's compiler. That's because you've defined Foo::bar as inline but not used it in foo.o You should either fix your autoinclude generation so that Foo::bar is defined inline in foo.hpp, or you should define it non-inline in foo.cpp Either way, foo.cpp still shouldn't include foo.hpp, despite your repeated claims it needs to. > How much do you spend in maintaining headers? answers welcomed from > other members as well. I don't see how it will save 40% of my time if I only have to edit one file instead of two. The change still has to be made *somewhere* and I spend more time deciding what to change and testing it than I do dealing with separating declarations from definitions.