cpplib: Start moving switch handling to front ends

Nicola Pero nicola@brainstorm.co.uk
Fri Aug 9 07:07:00 GMT 2002


> > I often wondered if by simply replacing these three statements with a new,
> > higher-level statement at the beginning of file, we wouldn't make users
> > happy.
> > 
> > Something like (pardon the roughness of my example, details can be fixed,
> > maybe a #pragma or whatever preprocessor magic, I'm just sketching an
> > idea)
> > 
> > #header-name Foundation/NSObject.h
> > 
> > only one '#header-name' would be allowed in the file, and it must be the
> > first non-comment code in the file; when encountering this, the
> > preprocessor would behave as if the three statements include-protection
> > triad had been found - that is something like
> > 
> > #ifndef _INCLUDE_NAME_Foundation/NSObject.h_H_
> > #define _INCLUDE_NAME_Foundation/NSObject.h_H_
> > 
> > at the beginning, and
> > 
> > #endif /* _INCLUDE_NAME_Foundation/NSObject.h_H_ 
> > 
> > at the end of the file (the name of the preprocessor #define is built from
> > the provided #header-name).
> 
> This is an interesting idea.  It avoids the inode problem, since the
> magic cookie is part of the file contents.

Precisely.


> I'd suggest that the right syntax is to give #pragma once an optional 
> argument; then we need only explain to users why this argument should 
> be used.

Ok - makes sense - I wouldn't mind some other syntax (even a dedicated
one) if it helps getting the support of Apple and core #import users :-)


> The cookie should be an identifier, for ease of parsing; you 
> should be able to recycle most of the existing include-guard code.
> 
> If you write the patch, and you can get buy-in from the ObjC community
> to use this instead of #import, I'd be willing to consider it for FSF GCC.

Unfortunately I'm leaving tomorrow for two weeks (holidays :-) so I have
to leave the discussion at this point.

I'll be very happy to write a patch when I get back if the idea is still
around.

Support from the ObjC community to use such a thing instead of #import
probably would take time.

The fact that the new syntax is widely available on newer GCCs would help;
maybe - if there is agreement that it's a good idea - we could start
providing the feature in the compiler, and start spreading the word that
you can use that now instead of #import.

I can investigate the feelings of the GNU ObjC community - which might
well be positive - they usually are with anything technically sound - and
GNUstep might start spreading the word :-) but if Apple goes consistently
against it, it's always going to be a hopeless battle for both fields,
like #include vs #import.

We can tell users to do #include <Foundation/Foundation.h>, we can write
that in all the doc, the examples, the mailing lists and whatever - but if
that makes their code impossible to port to Apple MacOSX because Apple
MacOSX headers are not protected against multiple inclusions (via #ifdefs
or via a new #pragma once xxx or some other mean inside the file itself)
and can only be included via #import (which is what it happens now), of
course users will think that #import <Foundation/Foundation.h> is more
portable than #include, since it works on both GNUstep and OSX, and they
will use #import - as they do now.  And there is little we can say against
such an argument.

So maybe a basic requirement for this thing to work and be accepted
largely by the ObjC programmers community is that all the major ObjC
parties/vendors agree it would be a good thing :-)



More information about the Gcc-patches mailing list