9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* Re: [9fans] the declaration of main()
@ 2001-04-26 19:42 Russ Cox
  2001-04-26 20:32 ` Dan Cross
                   ` (2 more replies)
  0 siblings, 3 replies; 51+ messages in thread
From: Russ Cox @ 2001-04-26 19:42 UTC (permalink / raw)
  To: 9fans

> No, that choice pretty much forced the existence of an APE.
> If the standard extern interfaces had been honored, Plan 9
> C could support both the native Plan 9 way of doing things
> *and* Standard C, without requiring any flags etc.

This is just bogus.  The whole point of Plan 9 is that
everything has been rethought.  What forced the existence
of an APE was the desire to compile and run some large legacy programs
without infecting the rest of the system with external
garbage.  Changing the definition of main to return int
would not eliminate the benefits of an APE any more than
anarchy would eliminate the benefits of prisons.

Russ


^ permalink raw reply	[flat|nested] 51+ messages in thread
* Re: [9fans] the declaration of main()
@ 2001-04-30 12:05 rob pike
  0 siblings, 0 replies; 51+ messages in thread
From: rob pike @ 2001-04-30 12:05 UTC (permalink / raw)
  To: 9fans

All right!  All right!  Enough!!!

I am the person who changed the definition of main.  At the time, we
had no plans of being compatible with anyone else's standard system.
On the other hand, we avoided gratuitious incompatibility and we just
plain missed the one for main.

Exit was changed to exits and it was unwise not to do something about
main, but it didn't cross my mind.  The reason is probably that we
were pushing for stronger-than-ANSI C, requiring prototypes, and I
knew we needed to make some changes because a different signature for
exit would cause trouble to existing programs (we changed creat to
create when we added the third argument, too) but I unconsciously knew
that the prototype of main wasn't in the headers and so I bet it just
never crossed my mind to change it.

Now please let that be the end of this discussion.  This group
deserves a higher signal to noise ratio.

-rob



^ permalink raw reply	[flat|nested] 51+ messages in thread
* Re: [9fans] the declaration of main()
@ 2001-04-30 10:44 forsyth
  0 siblings, 0 replies; 51+ messages in thread
From: forsyth @ 2001-04-30 10:44 UTC (permalink / raw)
  To: 9fans

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

i MEANT, for the implementation of all that Unix/POSIX/STDwhateveritis
that some seem to think is required.


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

From: "Douglas A. Gwyn" <DAGwyn@null.net>
To: 9fans@cse.psu.edu
Subject: Re: [9fans] the declaration of main()
Date: Mon, 30 Apr 2001 09:24:51 GMT
Message-ID: <3AEB4458.A948080D@null.net>

forsyth@caldo.demon.co.uk wrote:
> working code reaches those parts that whinges will not reach.

I already posted working code.

^ permalink raw reply	[flat|nested] 51+ messages in thread
* Re: [9fans] the declaration of main()
@ 2001-04-28 18:44 forsyth
  2001-04-30  9:24 ` Douglas A. Gwyn
  0 siblings, 1 reply; 51+ messages in thread
From: forsyth @ 2001-04-28 18:44 UTC (permalink / raw)
  To: 9fans

>>could we please end this?

i suggest that if an individual or group thinks they can produce
a better implementation of these things for Plan 9 that will
solve everyone's problems they set out and do it and let the list know when it's done.
working code reaches those parts that whinges will not reach.



^ permalink raw reply	[flat|nested] 51+ messages in thread
* Re: [9fans] the declaration of main()
@ 2001-04-28 17:57 forsyth
  2001-04-28 22:28 ` Dan Cross
  2001-04-30  9:25 ` Douglas A. Gwyn
  0 siblings, 2 replies; 51+ messages in thread
From: forsyth @ 2001-04-28 17:57 UTC (permalink / raw)
  To: 9fans

>>fashion.  He has a point, and indeed, someone today ran into problems
>>trying to mix `native' Plan 9 functions with functions taken from the
>>APE.  (Sorry, I didn't pay close enough attention to see who it was!)

>>True, one cannot easily mix and
>>match `native' Plan 9 and APE functions, but I think that might be a
>>good thing.

That was possibly bound to happen, not so much because of ANSI C but
because of all those Unix system calls.  You've got to implement them
somehow.  You've therefore got a choice: in the kernel or not.  To
mimic more precisely the effects or side-effects of Unix system calls,
or implement them at all (eg, select) the real Plan 9 system call is
called something else in the APE libraries (eg, _READ) and the name
`read' invokes something that maintains lots of state for `select' and
emulate some other aspects of Unix more accurately.

I don't want that cost in native Plan 9 programs.  I know, I know,
they could have used `p9read' or `sys_read' instead and avoided the
main POSIX names and then you could use both (but what about SPEC1132
or whatever it was -- people just get too carried away sometimes).

Even if they did all that, they'd unfortunately still need to specify
how the two sets of system calls interacted.  It's bad enough
implementing it in the first place.  See
/sys/src/ape/lib/ap/plan9/buf.prom for a Promela model of APE
select/read.  I found that interesting because when i wrote my own
operating system for 386 and Sun about 8 or 9 years ago,
select/read/write was the one thing i used Spin to model because the
definition was fiddly and I got it wrong the first time.
I also had to write a great MANY #include files.  There's a little joke
that the wc -l of the #include files for most Unix systems (esp. Linux)
is bigger than the source code of the Plan 9 kernels; and they're less readable.



^ permalink raw reply	[flat|nested] 51+ messages in thread
* Re: [9fans] the declaration of main()
@ 2001-04-27  6:57 nemo
  0 siblings, 0 replies; 51+ messages in thread
From: nemo @ 2001-04-27  6:57 UTC (permalink / raw)
  To: 9fans

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

C

(or John Lions had to rewrite 6th in C before his notes;
which I think he didn't) ☺


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

From: "Boyd Roberts" <boyd@planete.net>
To: <9fans@cse.psu.edu>
Subject: Re: [9fans] the declaration of main()
Date: Fri, 27 Apr 2001 01:50:48 +0200
Message-ID: <02a901c0ceab$b8286b40$e8b7c6d4@SOMA>

> C didn't really become widely used until after the 7th edition...

eh?  what was 6th ed written in?

^ permalink raw reply	[flat|nested] 51+ messages in thread
* Re: [9fans] the declaration of main()
@ 2001-04-26 20:58 forsyth
  2001-04-27  9:13 ` Douglas A. Gwyn
  0 siblings, 1 reply; 51+ messages in thread
From: forsyth @ 2001-04-26 20:58 UTC (permalink / raw)
  To: 9fans

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

>>Note that Forsyth's example is from 6th edition Unix, not 7th edition.
>>(The "s4/" in the source file name is a dead giveaway.)

i'm afraid not.

>>C didn't really become widely used until after the 7th edition, and
>>v7 C is really the ancestral root of most other implementations.  It is

the C compilers knew nothing of main, and if 7th edition really was the ancestral
root of most other implementations (which isn't so, because there were
some before 7th edition), they wouldn't have needed the invention
of EXIT_FAILURE and EXIT_SUCCESS.


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

From: Mike Haertel <mike@ducky.net>
To: 9fans@cse.psu.edu
Subject: Re: [9fans] the declaration of main()
Date: Thu, 26 Apr 2001 12:17:47 -0700 (PDT)
Message-ID: <200104261917.f3QJHlG03409@ducky.net>

Forsyth wrote:

>cpu% cat s4/crt0.s
>/ C runtime startoff

Note that Forsyth's example is from 6th edition Unix, not 7th edition.
(The "s4/" in the source file name is a dead giveaway.)

Here's the corresponding code fragment from 7th edition
/usr/src/libc/csu/crt0.s:

1:
	mov	r0,4(sp)
	mov	r0,_environ
	jsr	pc,_main
	cmp	(sp)+,(sp)+
	mov	r0,(sp)
	jsr	pc,*$_exit
	sys	exit

Here the int return value from main does indeed become the exit status.

C didn't really become widely used until after the 7th edition, and
v7 C is really the ancestral root of most other implementations.  It is
also the version of the language that most nearly coincided with the
publication of the 1st edition of "The C Programming Language".

^ permalink raw reply	[flat|nested] 51+ messages in thread
* Re: [9fans] the declaration of main()
@ 2001-04-26 18:23 forsyth
  2001-04-26 19:17 ` Mike Haertel
  2001-04-27  9:12 ` Douglas A. Gwyn
  0 siblings, 2 replies; 51+ messages in thread
From: forsyth @ 2001-04-26 18:23 UTC (permalink / raw)
  To: 9fans

>>Except for Plan 9's native (non-APE) and some standalone environments, main() *does*
>>in fact return an int, even if many programmers believed
>>otherwise.

oh well, i had good reason for my own belief:

cpu% cat s4/crt0.s
/ C runtime startoff

.globl	savr5

.globl	_main

start:
	setd
	mov	sp,r0
	mov	(r0),-(sp)
	tst	(r0)+
	mov	r0,2(sp)
	jsr	pc,_main
	cmp	(sp)+,(sp)+
	clr	r0
	sys	exit

.bss
savr5:	.=.+2

it doesn't look like main returns much to me.
given that the language hadn't even got void at that
point, how else was it to be declared but
	main(...)



^ permalink raw reply	[flat|nested] 51+ messages in thread
* Re: [9fans] the declaration of main()
@ 2001-04-24 10:32 rog
  2001-04-24 18:03 ` Steve Kilbane
  0 siblings, 1 reply; 51+ messages in thread
From: rog @ 2001-04-24 10:32 UTC (permalink / raw)
  To: 9fans

gwyn@arl.army.mil wrote:
> forsyth@vitanuova.com wrote:
> > it's unfortunately more error prone than void/exit.  for instance, it was
> > common to forget fflush() in the presence of setbuf/setvbuf in main for an auto buffer
> > and worse, that sometimes `worked' (until ported).
>
> I don't understand what you're talking about.

consider:

	#include <stdio.h>
	int main(void)
	{
		char buf[100];
		setvbuf(stdout, buf, _IOFBF, sizeof(buf));
		printf("hello, world\n");
		return 0;
	}



^ permalink raw reply	[flat|nested] 51+ messages in thread
* Re: [9fans] the declaration of main()
@ 2001-04-24  8:10 forsyth
  2001-04-26 15:55 ` Douglas A. Gwyn
  0 siblings, 1 reply; 51+ messages in thread
From: forsyth @ 2001-04-24  8:10 UTC (permalink / raw)
  To: 9fans

i realised later that i hadn't pointed out that regardless whether
int main was a good choice for the C standard, it had further
disadvantages in plan 9.

plan 9 does not use an integer for exit status: it uses a string.
if it's considered desirable to return status from main, it would
need to be char*, which is still different from the C standard.
it could remain int if a return of zero mapped to "" and
non-zero mapped to "glenda", but exits(char*) would still
need to be called by main in general.  if that appears at the
end of main, compilers that detect flowing off the end of
a function-returning-value will either give a diagnostic
or need some hack (another pragma, great) to know about
exits.  all right, you could have some function to set a int->char*
map for the return value of main but things are
already getting out of hand.   void main was the better choice.



^ permalink raw reply	[flat|nested] 51+ messages in thread
* Re: [9fans] the declaration of main()
@ 2001-04-24  0:59 okamoto
  2001-04-24  3:08 ` Boyd Roberts
  0 siblings, 1 reply; 51+ messages in thread
From: okamoto @ 2001-04-24  0:59 UTC (permalink / raw)
  To: 9fans

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

>okamoto@granite.cias.osakafu-u.ac.jp wrote:
>> I wonder why C99 employed that int main(),
>
>Existing practice, tracable back to UNIX.

I should have asked why C99 employed _fixed_ definition as the main()'s
return value to INT only.  I don't understand it, if the answer is "practice".

Kenji


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

From: "Douglas A. Gwyn" <gwyn@arl.army.mil>
To: 9fans@cse.psu.edu
Subject: Re: [9fans] the declaration of main()
Date: Mon, 23 Apr 2001 08:44:09 GMT
Message-ID: <3AD61574.8E819DA9@arl.army.mil>

okamoto@granite.cias.osakafu-u.ac.jp wrote:
> I wonder why C99 employed that int main(),

Existing practice, tracable back to UNIX.

The previous response was incomplete; int-valued main
is apparently supported per the C standard if the pcc
(POSIX) compilation environment is used instead of the
native Plan 9 environment.

^ permalink raw reply	[flat|nested] 51+ messages in thread
* Re: [9fans] the declaration of main()
@ 2001-04-23 19:33 dmr
  0 siblings, 0 replies; 51+ messages in thread
From: dmr @ 2001-04-23 19:33 UTC (permalink / raw)
  To: 9fans

Forsyth said,

 > although it was possible to return a status from main by 6th edition
 > (in 5th edition returning from main did exit(0)), and only su included
 > return from main, arguably wrongly in 5th edition and definitely so in
 > 6th.  when i looked recently, i could find only two commands using it
 > in 7th edition (makekey and graph, both returning 0).

5th and 6th did behave as Charles says.  The real difference
between them and the 7th was that almost no use was
made of status returns, (either exit() or return value of main),
in the earlier ones.  Many things just flowed off
the end of main.  Between 6th and 7th, most things were
fixed, in part because Bourne installed a version of his
shell that announced every non-zero termination.
Also things like make arrived, and non-zero returns
began to be treated more often as errors.

	Dennis


^ permalink raw reply	[flat|nested] 51+ messages in thread
* Re: [9fans] the declaration of main()
@ 2001-04-23 11:09 forsyth
  2001-04-23 11:31 ` Boyd Roberts
  2001-04-24  9:02 ` Douglas A. Gwyn
  0 siblings, 2 replies; 51+ messages in thread
From: forsyth @ 2001-04-23 11:09 UTC (permalink / raw)
  To: 9fans

>>okamoto@granite.cias.osakafu-u.ac.jp wrote:
>>> I wonder why C99 employed that int main(),

>>Existing practice, tracable back to UNIX.

although it was possible to return a status from main by 6th edition
(in 5th edition returning from main did exit(0)), and only su included
return from main, arguably wrongly in 5th edition and definitely so in
6th.  when i looked recently, i could find only two commands using it
in 7th edition (makekey and graph, both returning 0).  the UNIX programming
paper encouraged the use of exit to ensure reliable exit status for a caller.

return from main seemed to me to be used mainly by the System III/V crowd,
rather later.

it's unfortunately more error prone than void/exit.  for instance, it was
common to forget fflush() in the presence of setbuf/setvbuf in main for an auto buffer
and worse, that sometimes `worked' (until ported).

i like the plan 9 conventions, myself.



^ permalink raw reply	[flat|nested] 51+ messages in thread
* Re: [9fans] the declaration of main()
@ 2001-04-12  6:28 okamoto
  2001-04-23  8:44 ` Douglas A. Gwyn
  2001-04-23  8:48 ` Boyd Roberts
  0 siblings, 2 replies; 51+ messages in thread
From: okamoto @ 2001-04-12  6:28 UTC (permalink / raw)
  To: 9fans

nclude: /mail/fs/mbox/109/raw

I wonder why C99 employed that int main(), because I believe main()
makes a boundary between underlying OS and C language domain.
It means one should choose whichever s/he likes.  :-)

Kenji



^ permalink raw reply	[flat|nested] 51+ messages in thread
* [9fans] the declaration of main()
@ 2001-04-12  6:22 YAMANASHI Takeshi
  2001-04-12  6:25 ` andrey mirtchovski
  0 siblings, 1 reply; 51+ messages in thread
From: YAMANASHI Takeshi @ 2001-04-12  6:22 UTC (permalink / raw)
  To: 9fans

A number of Plan 9 commands declare their main() as
`void main(int argc, **argv)'.  How should I understand
this?

I believed that main() should be declared returning a int.
Please comfort me saying that this is pretty well with the
Plan 9 C compilers.

Thanks.
--
YAMANASHI Takeshi


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

end of thread, other threads:[~2001-04-30 12:05 UTC | newest]

Thread overview: 51+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-04-26 19:42 [9fans] the declaration of main() Russ Cox
2001-04-26 20:32 ` Dan Cross
2001-04-27 13:07   ` [9fans] purpose of APE Howard Trickey
2001-04-26 22:03 ` [9fans] the declaration of main() Boyd Roberts
2001-04-27  9:13 ` Douglas A. Gwyn
  -- strict thread matches above, loose matches on Subject: below --
2001-04-30 12:05 rob pike
2001-04-30 10:44 forsyth
2001-04-28 18:44 forsyth
2001-04-30  9:24 ` Douglas A. Gwyn
2001-04-28 17:57 forsyth
2001-04-28 22:28 ` Dan Cross
2001-04-30  9:25 ` Douglas A. Gwyn
2001-04-27  6:57 nemo
2001-04-26 20:58 forsyth
2001-04-27  9:13 ` Douglas A. Gwyn
2001-04-27 14:48   ` Boyd Roberts
2001-04-27 16:22     ` Douglas A. Gwyn
2001-04-27 18:24       ` William K. Josephson
2001-04-30  9:23         ` Douglas A. Gwyn
2001-04-27 19:38       ` Boyd Roberts
2001-04-28 15:54       ` Greg Hudson
2001-04-28 16:39         ` Dan Cross
2001-04-28 17:06           ` Boyd Roberts
2001-04-30  9:25           ` Douglas A. Gwyn
2001-04-26 18:23 forsyth
2001-04-26 19:17 ` Mike Haertel
2001-04-26 23:50   ` Boyd Roberts
2001-04-27 14:41     ` Douglas A. Gwyn
2001-04-27 15:40       ` Boyd Roberts
2001-04-27  9:12 ` Douglas A. Gwyn
2001-04-24 10:32 rog
2001-04-24 18:03 ` Steve Kilbane
2001-04-24  8:10 forsyth
2001-04-26 15:55 ` Douglas A. Gwyn
2001-04-24  0:59 okamoto
2001-04-24  3:08 ` Boyd Roberts
2001-04-23 19:33 dmr
2001-04-23 11:09 forsyth
2001-04-23 11:31 ` Boyd Roberts
2001-04-24  9:02 ` Douglas A. Gwyn
2001-04-24 12:09   ` Boyd Roberts
2001-04-26 16:05     ` Douglas A. Gwyn
2001-04-26 18:12       ` Boyd Roberts
2001-04-26 23:55       ` Boyd Roberts
2001-04-24 17:43   ` Greg Hudson
2001-04-26 15:55     ` Douglas A. Gwyn
2001-04-12  6:28 okamoto
2001-04-23  8:44 ` Douglas A. Gwyn
2001-04-23  8:48 ` Boyd Roberts
2001-04-12  6:22 YAMANASHI Takeshi
2001-04-12  6:25 ` andrey mirtchovski

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