public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Josh Triplett <josh@joshtriplett.org>
To: Patrick Palka <patrick@parcs.ath.cx>
Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Michal Marek <mmarek@suse.cz>, Sam Ravnborg <sam@ravnborg.org>,
	Rashika Kheria <rashika.kheria@gmail.com>
Subject: Re: #pragma once?
Date: Sun, 12 Jan 2014 21:53:45 -0800	[thread overview]
Message-ID: <20140113055344.GA12319@leaf> (raw)
In-Reply-To: <CA+C-WL_Z6TuWTO00gzgJo3+D-kHfjFBrfACqpaDCNxP23-LN_g@mail.gmail.com>

On Sun, Jan 12, 2014 at 11:14:56AM -0500, Patrick Palka wrote:
> On Mon, Jan 6, 2014 at 3:47 PM, Josh Triplett <josh@joshtriplett.org> wrote:
> > Does anyone have any objection to the use of "#pragma once" instead of
> > the usual #ifndef-#define-...-#endif include guard?  GCC, LLVM/clang,
> > and the latest Sparse all support either method just fine.  (I added
> > support to Sparse myself.)  Both have equivalent performance.  "#pragma
> > once" is simpler, and avoids the possibility of a typo in the defined
> > guard symbol.
> 
> Unfortunately in GCC #pragma once is slower and slightly buggier than
> regular include guards:
> 
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52566
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58770

The bug in question doesn't seem to apply to any likely use in the Linux
kernel.

As for performance, that benchmark seems somewhat odd to me, and I'm not
entirely convinced that it's representative of real-world projects,
which don't typically include ten thousand include files in one
compilation.  I've benchmarked the case of a single main.c including a
single guarded.h with both types of guards, and found the two guard
types indistinguishable in performance.  Beyond that, I'd say real-world
benchmarks would be preferable to artificial ones before declaring a
performance difference between the two types of guards.

- Josh Trpilett

      reply	other threads:[~2014-01-13  5:54 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-06 20:47 #pragma once? Josh Triplett
2014-01-06 21:00 ` Andrew Morton
2014-01-06 21:09   ` Josh Triplett
2014-01-06 21:33 ` Theodore Ts'o
2014-01-06 21:50   ` Dave Jones
2014-01-07  5:55 ` Sam Ravnborg
2014-01-07  9:48   ` Geert Uytterhoeven
2014-01-07 10:09     ` Michal Marek
2014-01-07 10:38       ` Josh Triplett
2014-01-07 10:50     ` Josh Triplett
2014-01-12 16:14 ` Patrick Palka
2014-01-13  5:53   ` Josh Triplett [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140113055344.GA12319@leaf \
    --to=josh@joshtriplett.org \
    --cc=akpm@linux-foundation.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mmarek@suse.cz \
    --cc=patrick@parcs.ath.cx \
    --cc=rashika.kheria@gmail.com \
    --cc=sam@ravnborg.org \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox