This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: #import, #pragma once yadda yadda mumble grumble
Jonathan Lennox wrote:-
> > 1) What definition of "the same file" are you using? When you say you "it
> > doesn't second-guess the filesystem", do you mean that the rule is just
> > "same absolute path, before any link or .. resolution"? There are cases
> > where that would break, but they would -- arguably -- deserve to be broken.
>
> The definition is "either a hash table hit (same search path position and
> filename) or the same last-modified date (st_mtime) and same content",
> with the "same content" check optimized by checking the file's length. I
> like that, nice and simple, and very portable; the last-modified date is
> almost certainly the one piece of file meta-data supported by every
> filesystem implemented.
If it doesn't hit anything in the hash table, it looks for a once-only
file with the same mtime and length (which, unless you're unlucky,
should fail for everything). If something matches it then falls back
to a byte-by-byte file comparison (so this is what happens to symlinks
and hardlinks, but users of those should expect to pay).
> > 2) What happens if you mix #include and #import of the same file?
>
> Nothing in particular; #import behavior is only affected by previous #import
> directives, not by #include, and #include ignores any previous #import's.
Yes.
> > 3) If you #import a file to a PCH file, and then later use the PCH file and
> > also re-#import the file outside of the PCH file, what happens? What if
> > it's on another host? (This could definitely fall into the category of
> > "deserves to break".)
>
> It still uses the same definition of sameness as above. So PCH'ing an
> #import'ed file, modifying it, and using both the PCH file and the #imported
> file -- or switching the PCH file to another machine where the headers were
> installed at a different time -- can potentially bring the file in twice.
> This is probably the right thing to do, though it might be nice if this
> could be warned for.
These are the kinds of corner cases I'm not convinced PCH does right.
Others include Kaveh's #pragma dependency. I'll make this more robust
eventually, with well-defined semantics.
> > These cases should probably be documented in the CPP manual (even if it's
> > just to explicitly make some behavior undefined).
>
> Still think this. :-)
Like I said, I'll follow up early next week with a doc patch.
Neil.