Patchwork cpp.texi: note obsolescence of "#pragma once" [DOC patch]

login
register
mail settings
Submitter Tom Browder
Date Sept. 8, 2010, 12:49 p.m.
Message ID <AANLkTi=C3wCwwnE3cbgN=Ai5XCvN2bbWoqUk8WHtbtWF@mail.gmail.com>
Download mbox | patch
Permalink /patch/64128/
State New
Headers show

Comments

Tom Browder - Sept. 8, 2010, 12:49 p.m.
Ian said that the cpp "#pragma once" is obsolete.  I think the cpp doc
needs updating to make that clear.  At the end is a patch to cpp.texi
to do that.

It has been tested with the trunk (rev 163997) and targets "make
info",  "make dvi", and "make pdf".

Regards,

-Tom

Thomas M. Browder, Jr.
Niceville, Florida
USA
Tom Browder - Sept. 8, 2010, 5:15 p.m.
On Wed, Sep 8, 2010 at 07:49, Tom Browder <tom.browder@gmail.com> wrote:
> Ian said that the cpp "#pragma once" is obsolete.  I think the cpp doc
> needs updating to make that clear.  At the end is a patch to cpp.texi
> to do that.

This patch is incorrect and will be resubmitted after bug 45599 is resolved.

-Tom

Patch

Index: cpp.texi
===================================================================
--- cpp.texi	(revision 163997)
+++ cpp.texi	(working copy)
@@ -948,7 +948,7 @@  twice.
 CPP optimizes even further.  It remembers when a header file has a
 wrapper @samp{#ifndef}.  If a subsequent @samp{#include} specifies that
 header, and the macro in the @samp{#ifndef} is still defined, it does
-not bother to rescan the file at all.
+not bother to open the file at all.

 You can put comments outside the wrapper.  They will not interfere with
 this optimization.
@@ -968,7 +968,8 @@  additional text, to avoid conflicts with
 CPP supports two more ways of indicating that a header file should be
 read only once.  Neither one is as portable as a wrapper @samp{#ifndef}
 and we recommend you do not use them in new programs, with the caveat
-that @samp{#import} is standard practice in Objective-C.
+that @samp{#import} is standard practice in Objective-C. Note that CPP
+optimizations obviate the need for these methods.

 @findex #import
 CPP supports a variant of @samp{#include} called @samp{#import} which
@@ -992,7 +993,8 @@  prevent the file from ever being read ag
 Another way to prevent a header file from being included more than once
 is with the @samp{#pragma once} directive.  If @samp{#pragma once} is
 seen when scanning a header file, that file will never be read again, no
-matter what.
+matter what.  (Note that @samp{#pragma once} is obsolete due to CPP
+optimizations and its use should be eliminated from GNU source files.)

 @samp{#pragma once} does not have the problems that @samp{#import} does,
 but it is not recognized by all preprocessors, so you cannot rely on it