9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: "Douglas A. Gwyn" <DAGwyn@null.net>
To: 9fans@cse.psu.edu
Subject: Re: [9fans] A probably stupid question on portability
Date: Wed, 24 Oct 2007 08:58:26 +0000	[thread overview]
Message-ID: <471E5851.BC2FB86D@null.net> (raw)
In-Reply-To: <13426df10710231210o2ac74db9l77d71813eebf95c6@mail.gmail.com>

ron minnich wrote:
> Is this construct portable at this point? c99 or whatever? Or is it gcc-centric?
> #if defined(_INCLUDED_GASNET_INTERNAL_H) && !defined(_IN_GASNET_INTERNAL_H)

That code could be used in a C99 program, but those identifiers
do not have standard meanings.  My guess is that you found that
in a header that uses one of the identifiers as an "idempotency
lock: to prevent the contents of the header from being processed
more than once no matter how many times the header is included.
Usually that is needed only when a header defines a typedef name.
The use of the other identifier is less clear, but is probably
something similar but in the opposite sense.

This idiom works in general, except that identifiers starting
with _ are (in this context) reserved for the C implementation
and should not be used in "user" source files.

/* start of file foo.h: */
#if !defined(INCLUDED_FOO_H) // could use #ifndef for single test
#define INCLUDED_FOO_H	// idempotency lock; won't get here later
...declarations and definitions here, including typedefs...
#endif
/* end of file foo.h */


      parent reply	other threads:[~2007-10-24  8:58 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-23 19:10 ron minnich
2007-10-23 19:14 ` Pietro Gagliardi
2007-10-23 20:03 ` Charles Forsyth
2007-10-23 20:12   ` Pietro Gagliardi
2007-10-24  8:58   ` Douglas A. Gwyn
2007-10-24  9:21     ` Charles Forsyth
2007-10-23 22:27 ` David Leimbach
2007-10-23 22:41   ` Pietro Gagliardi
2007-10-24  8:58 ` Douglas A. Gwyn [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=471E5851.BC2FB86D@null.net \
    --to=dagwyn@null.net \
    --cc=9fans@cse.psu.edu \
    /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;
as well as URLs for NNTP newsgroup(s).