9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] A probably stupid question on portability
@ 2007-10-23 19:10 ron minnich
  2007-10-23 19:14 ` Pietro Gagliardi
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: ron minnich @ 2007-10-23 19:10 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

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)


ron


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [9fans] A probably stupid question on portability
  2007-10-23 19:10 [9fans] A probably stupid question on portability ron minnich
@ 2007-10-23 19:14 ` Pietro Gagliardi
  2007-10-23 20:03 ` Charles Forsyth
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 9+ messages in thread
From: Pietro Gagliardi @ 2007-10-23 19:14 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

No #if in standard C compilers. Parse through cpp first. Otherwise it  
should work among compilers. As for the macros themselves, I have no  
idea.

On Oct 23, 2007, at 3:10 PM, 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)
>
>
> ron


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [9fans] A probably stupid question on portability
  2007-10-23 19:10 [9fans] A probably stupid question on portability 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-23 22:27 ` David Leimbach
  2007-10-24  8:58 ` Douglas A. Gwyn
  3 siblings, 2 replies; 9+ messages in thread
From: Charles Forsyth @ 2007-10-23 20:03 UTC (permalink / raw)
  To: 9fans

[-- Attachment #1: Type: text/plain, Size: 608 bytes --]

#if and the defined stuff are in even the older c standards, but it's
not defined to be part of the compiler (in plan 9, it's still in a separate cpp,
and usually that's not used, except with pcc, but see the -p option in 2c(1))

early on, cpp was fairly simple minded, part of the cc command(!), and
a c file had to have # at the start to be macro-processed.

the rot really set in with reiser
	This new version [of the preprocessor] was written by John F. Reiser and is from 5 to 12
	times faster than the old.
(but the input language was considerably more elaborate, and didn't people use it!)

[-- Attachment #2: Type: message/rfc822, Size: 3430 bytes --]

From: "ron minnich" <rminnich@gmail.com>
To: "Fans of the OS Plan 9 from Bell Labs" <9fans@cse.psu.edu>
Subject: [9fans] A probably stupid question on portability
Date: Tue, 23 Oct 2007 12:10:31 -0700
Message-ID: <13426df10710231210o2ac74db9l77d71813eebf95c6@mail.gmail.com>

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)


ron

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [9fans] A probably stupid question on portability
  2007-10-23 20:03 ` Charles Forsyth
@ 2007-10-23 20:12   ` Pietro Gagliardi
  2007-10-24  8:58   ` Douglas A. Gwyn
  1 sibling, 0 replies; 9+ messages in thread
From: Pietro Gagliardi @ 2007-10-23 20:12 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

The following

#if defined(_INCLUDED_GASNET_INTERNAL_H) && !defined 
(_IN_GASNET_INTERNAL_H)

is equivalent to

#ifdef _INCLUDED_GASNET_INTERNAL_H
#ifndef _IN_GASNET_INTERNAL_H

for the standard C compilers in Plan 9.  A goal of the Plan 9 kernel  
was to drop #if/#ifdef code and have a single C source code base that  
did not use this construct.  The compilers were adapted to fit this  
requirement, so they allow #ifdef, but disallow #if.  That is why a  
Standard C preprocessor, cpp(1), is provided

On Oct 23, 2007, at 4:03 PM, Charles Forsyth wrote:

> #if and the defined stuff are in even the older c standards, but it's
> not defined to be part of the compiler (in plan 9, it's still in a  
> separate cpp,
> and usually that's not used, except with pcc, but see the -p option  
> in 2c(1))
>
> early on, cpp was fairly simple minded, part of the cc command(!), and
> a c file had to have # at the start to be macro-processed.
>
> the rot really set in with reiser
> 	This new version [of the preprocessor] was written by John F.  
> Reiser and is from 5 to 12
> 	times faster than the old.
> (but the input language was considerably more elaborate, and didn't  
> people use it!)
>
> From: "ron minnich" <rminnich@gmail.com>
> Date: October 23, 2007 3:10:31 PM EDT
> To: "Fans of the OS Plan 9 from Bell Labs" <9fans@cse.psu.edu>
> Subject: [9fans] A probably stupid question on portability
> Reply-To: Fans of the OS Plan 9 from Bell Labs <9fans@cse.psu.edu>
>
>
> 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)
>
>
> ron
>


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [9fans] A probably stupid question on portability
  2007-10-23 19:10 [9fans] A probably stupid question on portability ron minnich
  2007-10-23 19:14 ` Pietro Gagliardi
  2007-10-23 20:03 ` Charles Forsyth
@ 2007-10-23 22:27 ` David Leimbach
  2007-10-23 22:41   ` Pietro Gagliardi
  2007-10-24  8:58 ` Douglas A. Gwyn
  3 siblings, 1 reply; 9+ messages in thread
From: David Leimbach @ 2007-10-23 22:27 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

[-- Attachment #1: Type: text/plain, Size: 278 bytes --]

On 10/23/07, ron minnich <rminnich@gmail.com> 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
> )
>
>
>
> ron
>

It's in the C99 standard.

[-- Attachment #2: Type: text/html, Size: 598 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [9fans] A probably stupid question on portability
  2007-10-23 22:27 ` David Leimbach
@ 2007-10-23 22:41   ` Pietro Gagliardi
  0 siblings, 0 replies; 9+ messages in thread
From: Pietro Gagliardi @ 2007-10-23 22:41 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

And C89 too

On Oct 23, 2007, at 6:27 PM, David Leimbach wrote:

>
>
> On 10/23/07, ron minnich <rminnich@gmail.com> 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)
>
>
>
> ron
>
> It's in the C99 standard.
>


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [9fans] A probably stupid question on portability
  2007-10-23 19:10 [9fans] A probably stupid question on portability ron minnich
                   ` (2 preceding siblings ...)
  2007-10-23 22:27 ` David Leimbach
@ 2007-10-24  8:58 ` Douglas A. Gwyn
  3 siblings, 0 replies; 9+ messages in thread
From: Douglas A. Gwyn @ 2007-10-24  8:58 UTC (permalink / raw)
  To: 9fans

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 */


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [9fans] A probably stupid question on portability
  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
  1 sibling, 1 reply; 9+ messages in thread
From: Douglas A. Gwyn @ 2007-10-24  8:58 UTC (permalink / raw)
  To: 9fans

Charles Forsyth wrote:
> the rot really set in with reiser
>         This new version [of the preprocessor] was written by John F. Reiser and is from 5 to 12
>         times faster than the old.
> (but the input language was considerably more elaborate, and didn't people use it!)

Virtually all the Reiser cpp features were used by a lot of code.
Some code even exploited differences between what K&R1 Appendix A
said and what the Reiser cpp actually did, such as substitution
within string literals.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [9fans] A probably stupid question on portability
  2007-10-24  8:58   ` Douglas A. Gwyn
@ 2007-10-24  9:21     ` Charles Forsyth
  0 siblings, 0 replies; 9+ messages in thread
From: Charles Forsyth @ 2007-10-24  9:21 UTC (permalink / raw)
  To: 9fans

>> (but the input language was considerably more elaborate, and didn't people use it!)
> 
> Virtually all the Reiser cpp features were used by a lot of code.

yes (i said `and didn't people use it!', not people didn't use it).
it was all a big mistake.
youthful enthusiasm, i suppose!


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2007-10-24  9:21 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-10-23 19:10 [9fans] A probably stupid question on portability 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 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).