Path: utzoo!utgpu!watmath!watdragon!rose!ccplumb From: ccplumb@rose.waterloo.edu (Colin Plumb) Newsgroups: gnu.gcc Subject: Re: #pragma once Message-ID: <18028@watdragon.waterloo.edu> Date: 9 Nov 89 19:44:43 GMT References: <8910300524.AA11104@sugar-bombs.ai.mit.edu> <1989Nov1.094352.24529@paris.ics.uci.edu> <522@loft386.UUCP> <305@jhereg.Minnetech.MN.ORG> Sender: daemon@watdragon.waterloo.edu Reply-To: ccplumb@rose.waterloo.edu (Colin Plumb) Distribution: gnu Organization: U. of Waterloo, Ontario Lines: 26 In article <305@jhereg.Minnetech.MN.ORG> mark@jhereg.UUCP (Mark H. Colburn) writes: > Ok, I'll finally admit it, I am a little confused as to why there is such a > construct as the #pragma once. > > If you want to avoid including the file twice, why not use the "standard" > method of enclosing the entire thing in "#ifdefs" as shown above: > > This works on any machine with a preprocessor, is portable across any > compiler, does not use a #pragma, and is in widespread use today. Also, > from the discussion which has ensued here about #pragma once, I assume that > it does not always work correctly. No, it works fine, it's just inefficient. The preprocessor has to open the file, parse it, including such pathological situations as printf("\ #endif /* \ */"); and all to include a few carriage returns in the source file. #pragma once lets the prorpocessor just skip over future #includes of the same file, not even opening the file for examination. With ANSI type-checking, header files are bigger than ever, and reducing time spent parsing them becomes more important. -- -Colin