From patchwork Wed Sep 8 12:49:42 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Browder X-Patchwork-Id: 64128 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id D68ADB6EEB for ; Wed, 8 Sep 2010 22:50:20 +1000 (EST) Received: (qmail 18593 invoked by alias); 8 Sep 2010 12:50:18 -0000 Received: (qmail 18583 invoked by uid 22791); 8 Sep 2010 12:50:17 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE X-Spam-Check-By: sourceware.org Received: from mail-bw0-f47.google.com (HELO mail-bw0-f47.google.com) (209.85.214.47) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 08 Sep 2010 12:50:04 +0000 Received: by bwz12 with SMTP id 12so47893bwz.20 for ; Wed, 08 Sep 2010 05:50:02 -0700 (PDT) Received: by 10.204.7.88 with SMTP id c24mr1600915bkc.172.1283950202229; Wed, 08 Sep 2010 05:50:02 -0700 (PDT) MIME-Version: 1.0 Received: by 10.204.84.197 with HTTP; Wed, 8 Sep 2010 05:49:42 -0700 (PDT) From: Tom Browder Date: Wed, 8 Sep 2010 07:49:42 -0500 Message-ID: Subject: cpp.texi: note obsolescence of "#pragma once" [DOC patch] To: gcc-patches Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org 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 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