[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: C Programming



On Sun, May 09, 2004 at 10:48:03PM -0500, Jeff Vian wrote:
> 
> 
> fredex wrote:
> 
> >On Sun, May 09, 2004 at 08:34:28AM -0500, Jeff Vian wrote:
> > 
> >
> >>fredex wrote:
> >>   
> >>
> >>>On Sat, May 08, 2004 at 10:46:37PM -0400, Wade Chandler wrote:
> >>>     
> >>>
> >>>>Gene Heskett wrote:
> >>>>       
> >>>>
> >>>>>On Saturday 08 May 2004 06:27, Trevor McNamara wrote:
> >>>>>         
> >>>>>
> >>>>>>Hello,
> >>>>>>           
> >>>>>>
> <snip>
> 
> >>>Not to be a negative-sounding force here, but I would urge you to NOT
> >>>ever use any of Herbert Schildt's books.
> >>>
> >>>Mr. Schildt is a skillful writer, his writing is clear and lucid. He
> >>>writes books on C and  C++ that very easily and clearly lead you down
> >>>the path to writing programs that are WRONG. he teaches bad practice in
> >>>C and C++ in clear and easily understood ways, such that if you follow
> >>>his advice you will learn his bad habits. one minor example is that he
> >>>is one of the many people who incorrectly teach that it is permissible
> >>>to declare main() as being of type void:
> >>>	void main (void)
> >>>		{
> >>>		...
> >>>		}
> >>>A little web searching, or spending a little time on groups.google.com
> >>>reading comp.lang.c will find you plenty of examples of why his books
> >>>are not a good way to learn C or C++. You can learn, in the same way,
> >>>of many other books that do teach the language(s) correctly.
> >>>
> >>>
> >>>     
> >>>
> >>Please explain why main cannot be of type void.
> >>   
> >>
> >
> >1. Because the ANSI/ISO standard for the C language requires that main
> >returns int.
> >
> >2. And if that isn't good enough for you, if you don't care about
> >standards, look at the practical implications. When you write a function:
> >
> > 
> >
> I expected a reasoned discussion, not flaming.

I didn't (and don't) view this as flaming. I merely state it that way
because I've seen discussion on this for years from people who aren't
interested in what the standard says (they say "Well, it works for me
on my compiler, so why shouldn't I use it???). So, I gave a practical
reason for why it matters.

> 
> <snip>
> 
> >>While I agree main is most often typed to int for the purpose of 
> >>returning a value designating completion with no errors or an error, 
> >>there is no *requirement* for that.
> >>   
> >>
> >
> >ah, but there is. Again, the language standard requires that main return
> >an integer.
> >
> >
> >So "why", you ask, "does the standard require main to return int?".
> >The original C standard was written to "codify existing practice". In many
> >environments (Unix, MS-DOS, probably other platforms) the return value of 
> >main is (or can be) used by the invoking program as a success or fail
> >status indicator. If the program doesn't return such a value the calling
> >program has no way to find out if hte program ran successfully or not.
> > 
> >
> true
> 
> >True, you CAN write a broken program that doesn't return anything from
> >main, but it's still going to hand back SOME value to the invoking program
> >as its status. if you don't provide a value, the code that calls main is
> >going to return something anyway, most likely some garbage/arbitrary
> >value it picked up from the place main's return should have been, but 
> >wasn't (since main is expected to return something but didn't).
> >
> >Understand, main() is NOT the first code to execute when a C program is
> >invoked. There's a chunk of "startup code", that is provided by the 
> >compiler vendor or a linkable library (invisible to the user) that
> >actually is invoked first, before main(). This code may do little in some
> >environments, or in other environments it may do a great deal of
> >stuff. But whatever it does, it (among other things) hands main its two
> >arguments, and receives an integer back from main. Changing the type of
> >main in your program does not change this code.
> >
> >
> > 
> >
> >>If you can provide *definitive documentation* of your statement that his 
> >>teaching is wrong in the requirements for function main() I would like 
> >>to see it.
> >>   
> >>
> >
> >See the language standard document.
> > 
> >
> I did look at that, all 550 pages of it.
> 
OK, then,  you surely saw the place(s) where it discusses main().

> >Or go ask this question in the newsgroup comp.lang.c where you'll either
> >be ignored as a troll, or else will get flamed, depending on the mood
> >this week.
> >
> >Mr. Schildt, for all his skill as a writer (and he is good, no denying
> >that!), is one (of many) people who perpetuate the myth that it's OK
> >to play fast and loose with the language standard. The result is that
> >so many people think that it IS OK to do so. But some day, somewhere in
> >the future, doing one of these things he teaches will nail your program
> >to the wall and you won't have a clue why it went wrong.
> > 
> >
> 
> This as certainly not the first author of programming books to violate 
> the standards in his methods.  I first learned C in the days of 

Did I say he was the first/only? No, I did not.

> Borland's Turbo C compiler, (taught at Drexel University in 
> Philadelphia), and the text book used in that class also ignored the 
> return type of main().  ( yes, I still have the text and verified this )
> 
> Are you planning to be this hostile about ALL books that you don't 
> happen to like.?

Again, it's not intended as hostility. It is intended as a warning to
people who will take a book and learn from it, especially those books
that teach incorrect programming. It's not the reader's fault that the
book teaches them wrongly. However someone who does not already know C
will not be able to discern those areas where the book teaches wrong
practice. There are books around that carefully do not teach bad practice,
many of them are recommended whenever this discussion comes up.

Again, the reason why I warn people about the books of Mr. Schildt is
that they too often teach bad practice, book after book. (no I haven't
read them all, but I have read some of them, and have seen plenty of
disucssion from those who both know C and have read his books).


I've said all I want to say on this. Please do not continue to
misinterpret what I'm trying to say (which is intended as a service to
those who might be lead astray by books that teach incorrect practice).

> 
> Your point would be much better made without hostility, but reasoned 
> agrument instead.  I noted where the standards define main and I am 
> satisfied with that.  All I originally asked for was the location where 
> it was defined that way, not a hostile diatribe.

And you got a pointer to the standard (I don't happen to have a copy
of it HERE right now to which I can refer so I could have given you
a more detailed reference). What you also got was a lengthy discussion
of why it matters, it was NOT a diatribe. sorry if you misinterpreted it.

Goodbye.


-- 
---- Fred Smith -- fredex fcshome stoneham ma us -----------------------------
                    The Lord detests the way of the wicked 
                  but he loves those who pursue righteousness.
----------------------------- Proverbs 15:9 (niv) -----------------------------

Attachment: pgp00188.pgp
Description: PGP signature


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]