9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* Re: [9fans] plan9's C compiler and // comments
       [not found] <1630899296@snellwilcox.com>
@ 2003-09-15 11:01 ` steve.simon
  2003-09-15 11:23   ` C H Forsyth
  2003-09-15 11:26   ` C H Forsyth
  0 siblings, 2 replies; 21+ messages in thread
From: steve.simon @ 2003-09-15 11:01 UTC (permalink / raw)
  To: 9fans

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

Hi,

ape/cpp also attempts to do single quote (') matching
inside C++ style comments.

Thus

	int fred = 0; 		// fred's number

causes cpp to spew. Its on my list of things to
track down but not at the top...

-Steve

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

From: 9fans@cse.psu.edu
To: 9fans@cse.psu.edu
Subject: Re: [9fans] plan9's C compiler and // comments
Date: Mon, 15 Sep 2003 04:19:35 +0100
Message-ID: <1630899296@snellwilcox.com>

Of course, even our cpp gets it wrong...  If you feel like fixing it,
might as well go whole hog.

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

* Re: [9fans] plan9's C compiler and // comments
  2003-09-15 11:01 ` [9fans] plan9's C compiler and // comments steve.simon
@ 2003-09-15 11:23   ` C H Forsyth
  2003-09-15 11:26   ` C H Forsyth
  1 sibling, 0 replies; 21+ messages in thread
From: C H Forsyth @ 2003-09-15 11:23 UTC (permalink / raw)
  To: 9fans

it was quicker to add the few lines of code to fix it
rather than discuss it further: so i did.



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

* Re: [9fans] plan9's C compiler and // comments
  2003-09-15 11:01 ` [9fans] plan9's C compiler and // comments steve.simon
  2003-09-15 11:23   ` C H Forsyth
@ 2003-09-15 11:26   ` C H Forsyth
  1 sibling, 0 replies; 21+ messages in thread
From: C H Forsyth @ 2003-09-15 11:26 UTC (permalink / raw)
  To: 9fans

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

i can only get that effect when i do NOT include the -+
option, but in that case it's not supposed to do C++ comments
so the effect is correct.

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

[-- Attachment #2.1.1: Type: text/plain, Size: 230 bytes --]

Hi,

ape/cpp also attempts to do single quote (') matching
inside C++ style comments.

Thus

	int fred = 0; 		// fred's number

causes cpp to spew. Its on my list of things to
track down but not at the top...

-Steve

[-- Attachment #2.1.2: Type: message/rfc822, Size: 608 bytes --]

From: 9fans@cse.psu.edu
To: 9fans@cse.psu.edu
Subject: Re: [9fans] plan9's C compiler and // comments
Date: Mon, 15 Sep 2003 04:19:35 +0100
Message-ID: <1630899296@snellwilcox.com>

Of course, even our cpp gets it wrong...  If you feel like fixing it,
might as well go whole hog.

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

* Re: [9fans] plan9's C compiler and // comments
  2003-09-15  3:14 ` mirtchov
  2003-09-15  3:19   ` David Presotto
  2003-09-15  7:51   ` boyd, rounin
@ 2003-09-15  8:23   ` boyd, rounin
  2 siblings, 0 replies; 21+ messages in thread
From: boyd, rounin @ 2003-09-15  8:23 UTC (permalink / raw)
  To: 9fans

> I admit as was truly disappointed when I didn't read "people who
> program using the preprocessor should be shot" in Boyd's post :)

or as grampaw pettibone woulda said:

    Land a goshen, only a dadburned idiot would fly
    into the break at five hundred knots.



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

* Re: [9fans] plan9's C compiler and // comments
  2003-09-15  7:49 ` boyd, rounin
@ 2003-09-15  8:01   ` Geoff Collyer
  0 siblings, 0 replies; 21+ messages in thread
From: Geoff Collyer @ 2003-09-15  8:01 UTC (permalink / raw)
  To: 9fans

cpp gets abused, but we need it (or m4 or something of the sort), if
only for #include, so it's not completely unnecessary.  The bad old
days, when we walked 5 miles uphill to and from school, were not
pretty: when cpp was an optional compiler pass and /usr/include didn't
exist yet, only the kernel bothered to #include headers, and the
number of bugs in V6 Unix programs because somebody had copied a
struct declaration out of a manual page and then the real struct
changed (or they had copied it incorrectly in the first place) was
considerable.



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

* Re: [9fans] plan9's C compiler and // comments
  2003-09-15  3:21 ` Bruce Ellis
@ 2003-09-15  8:00   ` boyd, rounin
  0 siblings, 0 replies; 21+ messages in thread
From: boyd, rounin @ 2003-09-15  8:00 UTC (permalink / raw)
  To: 9fans

> I did the special /**/ stuff because some crappy code depends on
> them being elided.  I probably should have done // as well but
> decided not to for some reason lost in the past.

i wrote a cpp once, when i really wasn't up to the job.

the problem is:

    do you remove the comment from the macro text or just
    leave it in?

in the case of /* ... */ it doesn't make a lotta difference 'cos
during the expansion they could dissappear.

if the case of // they had better be removed from the macro
text 'cos when the expansion comes along you are in a
'world of pain'.

reiser's cpp was blinding fast, and almost unreadable so
you had your work cut out to work out the semantics of
the damn thing.

he had worked out this insight that you were just writing
a _slightly_ smarter version of cat;  it didn't tokenise
much and used one i/o buffer to do all the dirty work.



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

* Re: [9fans] plan9's C compiler and // comments
  2003-09-15  3:14 ` mirtchov
  2003-09-15  3:19   ` David Presotto
@ 2003-09-15  7:51   ` boyd, rounin
  2003-09-15  8:23   ` boyd, rounin
  2 siblings, 0 replies; 21+ messages in thread
From: boyd, rounin @ 2003-09-15  7:51 UTC (permalink / raw)
  To: 9fans

> I admit as was truly disappointed when I didn't read "people who
> program using the preprocessor should be shot" in Boyd's post :)

i was too busy with awk and thought that anyone using // comments
AND the preprocessor was a fool.



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

* Re: [9fans] plan9's C compiler and // comments
  2003-09-15  3:06 David Presotto
                   ` (2 preceding siblings ...)
  2003-09-15  4:06 ` Enache Adrian
@ 2003-09-15  7:49 ` boyd, rounin
  2003-09-15  8:01   ` Geoff Collyer
  3 siblings, 1 reply; 21+ messages in thread
From: boyd, rounin @ 2003-09-15  7:49 UTC (permalink / raw)
  To: 9fans

> I think nobody ever thought of or cared to do it before because
> we frown so much on programming with the preprocessor.

is it the plan 9 C compiler paper that states that use of the
preprocessor has been cut down to the core and its overuse
is discouraged and, in fact, unnecessary?

iirc

i have awk regression tests to run, which are running quite nicely
against /bin/awk which should allow me to incorporate some of
bwk's fixes and then i'll run 'em on my native 'port'.



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

* Re: [9fans] plan9's C compiler and // comments
  2003-09-15  1:23   ` boyd, rounin
@ 2003-09-15  7:21     ` Charles Forsyth
  0 siblings, 0 replies; 21+ messages in thread
From: Charles Forsyth @ 2003-09-15  7:21 UTC (permalink / raw)
  To: 9fans

>>things were not helped by the complexity of the reiser cpp either.

the remarkable thing is that later work on C ADDED to the preprocessor,
and even more later!
``when you're in a hole ...''

fortunately, it must be said that even in some of the worst code i've seen
the authors kept to the simpler constructions.  the main problems in practice
tend to be the use of it at all (eg, Linux enumerating arbitrarily many platforms in a single file
controlled by #ifdef!), and overly complex #if expressions (which, not being
checked much can easily go wrong).  a little gem recently was ``#if ndef ...''.



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

* Re: [9fans] plan9's C compiler and // comments
  2003-09-15  3:19   ` David Presotto
@ 2003-09-15  7:11     ` Charles Forsyth
  0 siblings, 0 replies; 21+ messages in thread
From: Charles Forsyth @ 2003-09-15  7:11 UTC (permalink / raw)
  To: 9fans

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

try adding -+ to allow C++ comments.
worked for me.

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

From: David Presotto <presotto@closedmind.org>
To: 9fans@cse.psu.edu
Subject: Re: [9fans] plan9's C compiler and // comments
Date: Sun, 14 Sep 2003 23:19:35 -0400
Message-ID: <091866070e78bbd2b2d1b8c920fadb9d@plan9.bell-labs.com>

Of course, even our cpp gets it wrong...  If you feel like fixing it,
might as well go whole hog.

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

* Re: [9fans] plan9's C compiler and // comments
  2003-09-15  4:06 ` Enache Adrian
@ 2003-09-15  7:03   ` Charles Forsyth
  0 siblings, 0 replies; 21+ messages in thread
From: Charles Forsyth @ 2003-09-15  7:03 UTC (permalink / raw)
  To: 9fans

>>incompatibilities -- but then the whole '#if A && defined(B)' madness
>>should be probably put in too).

no, there's already a useful, separate cpp, from a venerable source,
that isolates all that complexity.

use -p with ?c to get it when you need it.
use -+ as well if you need // comments.
(with it, cpp handles the #define ... // case being discussed.)



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

* Re: [9fans] plan9's C compiler and // comments
  2003-09-15  3:06 David Presotto
  2003-09-15  3:14 ` mirtchov
  2003-09-15  3:21 ` Bruce Ellis
@ 2003-09-15  4:06 ` Enache Adrian
  2003-09-15  7:03   ` Charles Forsyth
  2003-09-15  7:49 ` boyd, rounin
  3 siblings, 1 reply; 21+ messages in thread
From: Enache Adrian @ 2003-09-15  4:06 UTC (permalink / raw)
  To: 9fans; +Cc: enache

On Sun, Sep 14, 2003 a.d., David Presotto wrote:
> Looks like just the opposite to me.  /**/ comments are handled specially.
> The prepocessor doesn't know anything about // comments.  If you want to
> change it, I wouldn't mind.  I think nobody ever thought of or cared to
> do it before because we frown so much on programming with the preprocessor.

Never mind. I stumbled on this when trying to get stuff cut-n-pasted
from external headers working.
I actually fixed that issue with sed.

This should be probably changed only if the compiler is ported outside
plan9 (to make it work like MSVC or gcc, in order to avoid gratuitous
incompatibilities -- but then the whole '#if A && defined(B)' madness
should be probably put in too).

Regards,
Adi


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

* Re: [9fans] plan9's C compiler and // comments
  2003-09-15  3:06 David Presotto
  2003-09-15  3:14 ` mirtchov
@ 2003-09-15  3:21 ` Bruce Ellis
  2003-09-15  8:00   ` boyd, rounin
  2003-09-15  4:06 ` Enache Adrian
  2003-09-15  7:49 ` boyd, rounin
  3 siblings, 1 reply; 21+ messages in thread
From: Bruce Ellis @ 2003-09-15  3:21 UTC (permalink / raw)
  To: 9fans

I did the special /**/ stuff because some crappy code depends on
them being elided.  I probably should have done // as well but
decided not to for some reason lost in the past.

brucee
----- Original Message -----
From: "David Presotto" <presotto@closedmind.org>
To: <enache@rdslink.ro>; <9fans@cse.psu.edu>
Sent: Monday, September 15, 2003 1:06 PM
Subject: Re: [9fans] plan9's C compiler and // comments


> Looks like just the opposite to me.  /**/ comments are handled specially.
> The prepocessor doesn't know anything about // comments.  If you want to
> change it, I wouldn't mind.  I think nobody ever thought of or cared to
> do it before because we frown so much on programming with the preprocessor.
>
> The // at the end of your endif makes it through only because everything after the
> endif is ignored.


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

* Re: [9fans] plan9's C compiler and // comments
  2003-09-15  3:14 ` mirtchov
@ 2003-09-15  3:19   ` David Presotto
  2003-09-15  7:11     ` Charles Forsyth
  2003-09-15  7:51   ` boyd, rounin
  2003-09-15  8:23   ` boyd, rounin
  2 siblings, 1 reply; 21+ messages in thread
From: David Presotto @ 2003-09-15  3:19 UTC (permalink / raw)
  To: 9fans

Of course, even our cpp gets it wrong...  If you feel like fixing it,
might as well go whole hog.


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

* Re: [9fans] plan9's C compiler and // comments
  2003-09-15  3:06 David Presotto
@ 2003-09-15  3:14 ` mirtchov
  2003-09-15  3:19   ` David Presotto
                     ` (2 more replies)
  2003-09-15  3:21 ` Bruce Ellis
                   ` (2 subsequent siblings)
  3 siblings, 3 replies; 21+ messages in thread
From: mirtchov @ 2003-09-15  3:14 UTC (permalink / raw)
  To: 9fans

> I think nobody ever thought of or cared to
> do it before because we frown so much on programming with the preprocessor.

I admit as was truly disappointed when I didn't read "people who
program using the preprocessor should be shot" in Boyd's post :)




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

* Re: [9fans] plan9's C compiler and // comments
@ 2003-09-15  3:06 David Presotto
  2003-09-15  3:14 ` mirtchov
                   ` (3 more replies)
  0 siblings, 4 replies; 21+ messages in thread
From: David Presotto @ 2003-09-15  3:06 UTC (permalink / raw)
  To: enache, 9fans

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

Looks like just the opposite to me.  /**/ comments are handled specially.
The prepocessor doesn't know anything about // comments.  If you want to
change it, I wouldn't mind.  I think nobody ever thought of or cared to
do it before because we frown so much on programming with the preprocessor.

The // at the end of your endif makes it through only because everything after the
endif is ignored.

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

From: Enache Adrian <enache@rdslink.ro>
To: 9fans@cse.psu.edu
Subject: Re: [9fans] plan9's C compiler and // comments
Date: Mon, 15 Sep 2003 05:21:21 +0300
Message-ID: <20030915022121.GC1290@ratsnest.hole>

> On Sun, Sep 14, 2003 a.d., David Presotto wrote:
> > It accepts it just fine.  You're just defining a macro as
> >
> > 	"wow!"	// this won't work
> >
> > and when it gets expanded in the exits you get
> >
> > void main() { exits("wow!"	// this won't work); }

Judging about what I understand of cmd/cc/macbody:237-260,
ex. the /**/ comments are not passed through macros to be dealt with
later, but discarded during the parsing of the '#define' directive.

So the handling of '//' comments is just special in this case.

Regards,
Adi

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

* Re: [9fans] plan9's C compiler and // comments
  2003-09-15  1:16 ` Enache Adrian
  2003-09-15  1:23   ` boyd, rounin
@ 2003-09-15  2:21   ` Enache Adrian
  1 sibling, 0 replies; 21+ messages in thread
From: Enache Adrian @ 2003-09-15  2:21 UTC (permalink / raw)
  To: 9fans

> On Sun, Sep 14, 2003 a.d., David Presotto wrote:
> > It accepts it just fine.  You're just defining a macro as
> >
> > 	"wow!"	// this won't work
> >
> > and when it gets expanded in the exits you get
> >
> > void main() { exits("wow!"	// this won't work); }

Judging about what I understand of cmd/cc/macbody:237-260,
ex. the /**/ comments are not passed through macros to be dealt with
later, but discarded during the parsing of the '#define' directive.

So the handling of '//' comments is just special in this case.

Regards,
Adi


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

* Re: [9fans] plan9's C compiler and // comments
  2003-09-15  1:16 ` Enache Adrian
@ 2003-09-15  1:23   ` boyd, rounin
  2003-09-15  7:21     ` Charles Forsyth
  2003-09-15  2:21   ` Enache Adrian
  1 sibling, 1 reply; 21+ messages in thread
From: boyd, rounin @ 2003-09-15  1:23 UTC (permalink / raw)
  To: 9fans

> Notice however that this is different from other compilers/preprocessors.
> (FWIW, I prefer to stick to old '/* ... */' comments).

the problem didn't exist till C++ added //

things were not helped by the complexity of the reiser cpp either.



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

* Re: [9fans] plan9's C compiler and // comments
  2003-09-15  1:02 David Presotto
@ 2003-09-15  1:16 ` Enache Adrian
  2003-09-15  1:23   ` boyd, rounin
  2003-09-15  2:21   ` Enache Adrian
  0 siblings, 2 replies; 21+ messages in thread
From: Enache Adrian @ 2003-09-15  1:16 UTC (permalink / raw)
  To: 9fans

On Sun, Sep 14, 2003 a.d., David Presotto wrote:
> It accepts it just fine.  You're just defining a macro as
>
> 	"wow!"	// this won't work
>
> and when it gets expanded in the exits you get
>
> void main() { exits("wow!"	// this won't work); }
>
> which eats up the '); }' at the end of the function.

Thanks for clarifying this.
Notice however that this is different from other compilers/preprocessors.
(FWIW, I prefer to stick to old '/* ... */' comments).

Regards,
Adi


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

* [9fans] plan9's C compiler and // comments
@ 2003-09-15  1:02 David Presotto
  2003-09-15  1:16 ` Enache Adrian
  0 siblings, 1 reply; 21+ messages in thread
From: David Presotto @ 2003-09-15  1:02 UTC (permalink / raw)
  To: 9fans

It accepts it just fine.  You're just defining a macro as

	"wow!"	// this won't work

and when it gets expanded in the exits you get

void main() { exits("wow!"	// this won't work); }

which eats up the '); }' at the end of the function.


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

* [9fans] plan9's C compiler and // comments
@ 2003-09-15  0:49 Enache Adrian
  0 siblings, 0 replies; 21+ messages in thread
From: Enache Adrian @ 2003-09-15  0:49 UTC (permalink / raw)
  To: 9fans

The C compiler accepts '//..' C++ -like comments, but not in '#define'
directives.

-----------------------
#include <u.h>
#include <libc.h>

// this one OK
#ifndef FOO
#define EXITS	"wow!"	// this won't work
#endif // this one OK too

void main() { exits(EXITS); }
-----------------------

Is this deliberate behaviour ?

(sorry if it's already fixed, my plan9 is a bit out of date).

Thanks,
Adi


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

end of thread, other threads:[~2003-09-15 11:26 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <1630899296@snellwilcox.com>
2003-09-15 11:01 ` [9fans] plan9's C compiler and // comments steve.simon
2003-09-15 11:23   ` C H Forsyth
2003-09-15 11:26   ` C H Forsyth
2003-09-15  3:06 David Presotto
2003-09-15  3:14 ` mirtchov
2003-09-15  3:19   ` David Presotto
2003-09-15  7:11     ` Charles Forsyth
2003-09-15  7:51   ` boyd, rounin
2003-09-15  8:23   ` boyd, rounin
2003-09-15  3:21 ` Bruce Ellis
2003-09-15  8:00   ` boyd, rounin
2003-09-15  4:06 ` Enache Adrian
2003-09-15  7:03   ` Charles Forsyth
2003-09-15  7:49 ` boyd, rounin
2003-09-15  8:01   ` Geoff Collyer
  -- strict thread matches above, loose matches on Subject: below --
2003-09-15  1:02 David Presotto
2003-09-15  1:16 ` Enache Adrian
2003-09-15  1:23   ` boyd, rounin
2003-09-15  7:21     ` Charles Forsyth
2003-09-15  2:21   ` Enache Adrian
2003-09-15  0:49 Enache Adrian

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).