tags:

views:

29

answers:

1

Sometimes I need to use a gcc for cross-platform work, and sometimes gcc really amuses me with its warnings. For example:

#pragma once in a main file

This is very informative warning, but I really don't know what a 'main file' IS in terminology of gcc and WHY it must not contain #pragma once :). So, does any documentation exist that covers all gcc warnings and errors (mostly warnings, errors are trivial) with some comments on them?

+1  A: 

The objective of '#pragma once' is to prevent a header from being reincluded. If you have it in a source file (usually a '.c' file), you won't be reading that twice (normally - I do know of a source file that reincludes itself [and I don't like it]; it does not use or want #pragma once, though!). So, a 'main file' in this context is one listed on the command line, for instance, rather than a header.

As to the subject matter of the question - the GCC manual does not seem to have a comprehensive list. I don't know whether there actually is one.

Jonathan Leffler
But it is in the header. A precompiled header.
Eye of Hell
A precompiled header gets built, so it's a "main file" when building it -- and `#pragma once` presumably only makes sense when the preprocessor is doing inclusion, and not with precompiled headers.
hobbs
@hobbs: Yes. `gcc -c so.h` yields`so.h:1:9: warning: #pragma once in main file` when compiling the header into a precompiled header. I'm not sure if there's a good way to suppress that warning.
Jonathan Leffler
I don't know how representative it is, but a 2 line header (so.h) containing #pragma once and `static int abc = ABC;` expanded into a 2MB pre-compiled header (so.h.gch) on a Mac Mini with GCC 4.2.1.
Jonathan Leffler