Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!usc!cs.utexas.edu!uunet!watmath!watmsg!gjditchfield From: gjditchfield@watmsg.waterloo.edu (Glen Ditchfield) Newsgroups: gnu.gcc Subject: Re: #pragma once Message-ID: <30876@watmath.waterloo.edu> Date: 30 Oct 89 21:55:55 GMT References: <8910300524.AA11104@sugar-bombs.ai.mit.edu> Sender: daemon@watmath.waterloo.edu Reply-To: gjditchfield@watmsg.waterloo.edu (Glen Ditchfield) Distribution: gnu Organization: U. of Waterloo, Ontario Lines: 36 In article dld@F.GP.CS.CMU.EDU (David Detlefs) writes: > ... The best idea I have ever heard along these lines was recently >reiterated by John Nagle on comp.lang.c++ (I don't know if it's original >with him): > >have cpp recognize files of the common form > >: > >#ifndef > >#endif > > > ... Note that this gets all the performance savings of #pragma once, >while maintaining ANSI semantics. If you read rms's post again, >you'll note that you are supposed to use *both* #pragma once and the >#ifndef style. This proposal obviates the need for the #pragma once. Some other, weaker points: - For better or worse, the "Nagle" system would allow programmers to force reinclusion by undefining . I don't how to override "#pragma once"; I'll bet there is a way, and I'll bet that it would vary among compilers that implement "#pragma once". - I often pass my C++ code through g++ and through AT&T's system. The obsolescent cpp used here with cfront complains that it doesn't know what to do with "#pragma", so I've gotten out of the habit of using "#pragma once". (I agree that the proper thing to do is to change preprocessors, but ...) - Other systems have already taken other approaches. If I remember correctly, one C compiler had "#pragma idempotent", while Objective C's preprocessor tackled the problem from the other end with "#import". "#ifndef/#endif" works for all of them. I think it's easier to provide an optimization for this idiom than to get all implementors to agree to a single extension.