Re: A note on Peter Seebach's vicious little tirade
- From: pete <pfiland@xxxxxxxxxxxxxx>
- Date: Sun, 04 Oct 2009 05:44:25 -0400
Keith Thompson wrote:
Julienne Walker <happyfrosty@xxxxxxxxxxx> writes:
On Oct 2, 7:44 am, "bartc" <ba...@xxxxxxxxxx> wrote:
"Page 163
You may also declare main() as void if it does not return a value.
Specifically untrue. ANSI mandates two declarations for main, and says that
main may have declarations compatible with those. Both return int."
My K&R2 uses "main()" yet is highly thought of. Trivial.
The only problem with K&R2's usage is that in the early chapters a
return statement is omitted, which is technically undefined behavior.
However, this was a pedagogical choice that is explained shortly
after, and correct code is provided from then on, IIRC. I won't attack
or defend their choice to allow undefined behavior for simplicity
sake, but this is quite different from doing so (regardless of the
reason) and then failing to correct the error both in explanation and
example.
The first sample program in K&R2 is:
#include <stdio.h>
main()
{
printf("hello, world\n");
}
I suggest that there are actually three problems with that code:
3. It doesn't return a value.
That point is addressed by the the text of the book.
1.7 Functions
In the interests of simplicity, we have omitted return statements
from our main functions up to this point, but we will include them
hereafter, as a reminder that programs should return status to their
environment.
--
pete
.
- References:
- A note on Peter Seebach's vicious little tirade
- From: spinoza1111
- Re: A note on Peter Seebach's vicious little tirade
- From: bartc
- Re: A note on Peter Seebach's vicious little tirade
- From: Julienne Walker
- Re: A note on Peter Seebach's vicious little tirade
- From: Keith Thompson
- A note on Peter Seebach's vicious little tirade
- Prev by Date: Re: File Size - Big File Size
- Next by Date: Re: variadic functions
- Previous by thread: Re: A note on Peter Seebach's vicious little tirade
- Next by thread: Re: A note on Peter Seebach's vicious little tirade
- Index(es):
Relevant Pages
|
Loading