This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: #import and PCH


Neil Booth <neil@daikokuya.co.uk> writes:

>> > How about just removing #import?  What about #pragma once?
>> 
>> #pragma once is a problem for another day.
>
> But it has problems that are identical to #import in every way.  At
> present, we have #include which works as well as we can make it.
> Then we have #import and #pragma once, which behave identically
> brokenly.

I would like to point out that the reason the #include / wrapper
#ifndef optimization is not broken is, the #ifndef causes the Right
Thing to happen even if CPP can't optimize out the reinclusion.  This
is also why '#pragma GCC once _HEADER_FILE_TAG' would work, assuming
someone implemented it.

#import and bare #pragma once are intrinsically fragile in the absence
of a way to prove that two files are the same.  Inode/device pairs do
that, but they're not stable across file systems, and you already
brought up the possibility of copying a PCH from one machine to
another, yes?  So that won't work.  I suppose you could take a
cryptographic checksum of the target file when you see #import or
#pragma once.  That'd work everywhere.  Might be too slow though.

> I don't think making #import different yet again is progress.  I am
> convinced that two implementations of the same thing, namely
> multiple inclusion, in the code base is worse than the current
> situation.

I agree.

> But you labelled it built-in.  They're not dumped with -dM.  And you
> have introduced the #import <foo.h> and #import <./foo.h> inconsistency
> that you noted.  We don't have that at present.

Yah, I'm not happy with this inconsistency either.

>> >  What if #import <a.h> is followed by #include <a.h> ?
>> 
>> This is an intentional change.
>
> Silently?  With what justification?  I don't think this is progress.
> This looks like documenting around a broken implementation.

Note that the CPP manual has said

     In the present implementation, a single use of #import will
     prevent the file from ever being read again, by either #import or
     #include. You should not rely on this; do not use both #import
     and #include to refer to the same header file.

since 3.0.  So I am not going to cry if we have to change that.  But I
would prefer that we didn't.

> I had hoped we could just scrap #import and #pragma once.  Nicola's
> message leaves me quite pessimistic - it seems that the stubborn
> insistance of some people in Apple, which to be honest I can quite
> understand, is impeding us doing the right thing in FSF GCC.
> However, this problem is not one that will go away by ignoring it.

I'd like to throw in RMS's assessment of #import (which has been in
the manual since 2.7 if not before):

     #import is not a well designed feature. It requires the users of
     a header file to know that it should only be included once. It is
     much better for the header file's implementor to write the file
     so that users don't need to know this. Using a wrapper #ifndef
     accomplishes this goal.

IMO this is a good language-design reason to get rid of #import, never
mind the implementation problems.

zw


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]