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

Re: C Programming





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.

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

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

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.





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