The C++ primer 5th Edition (by Lippman ), an example of bad way to express something.
-
So I have started reading the book , and on chapter 6 Functions, 6.3 Return Types and the return statement, he says : "Return from main There is one exception to the rule that a function with a return type other than void must return a value: The main function is allowed to terminate without a return. If control reaches the end of main and there is no return, then the compiler implicitly inserts a return of 0". And I am thinking : What? Why mr. Lippman ? why do you have to express a simple idea in such a complicated way , and mention something that is on the edge of inaccuracy ? You should say : There is NO exception to the rule that a function with a return type other than void must return a value. But because we , the programmers , do not like to type things when not necessary , the compiler lets us omit typing explicitly the return 0; in function main.So instead of
int main() {
//some code here
return 0;
}you are allowed to type
int main() {
//your code
}and the compiler will happily insert the implicit return 0; so main() returns a value as it should. I know it is slightly longer as text , but it is what you should mention. I have many other examples from this book on which I could complain. Generally it is a correct book , and anyone who wants to learn C++ cannot avoid it, but although the information is there (and it is correct) it always fails to present that information in a way that will help you to remember it , or fails to aid in categorizing and summarizing the new information. I constantly feel that the only way for this book to be useful is to use it as a primary trustful source for writing my own notes (and they would be as many pages as the book !). But anyway , I am doing all the exercises , and keep reading. I plan to read on parallel the book from I.Horton, Beginning C++ (2015 edition) to get some coverage for C++14.
-
So I have started reading the book , and on chapter 6 Functions, 6.3 Return Types and the return statement, he says : "Return from main There is one exception to the rule that a function with a return type other than void must return a value: The main function is allowed to terminate without a return. If control reaches the end of main and there is no return, then the compiler implicitly inserts a return of 0". And I am thinking : What? Why mr. Lippman ? why do you have to express a simple idea in such a complicated way , and mention something that is on the edge of inaccuracy ? You should say : There is NO exception to the rule that a function with a return type other than void must return a value. But because we , the programmers , do not like to type things when not necessary , the compiler lets us omit typing explicitly the return 0; in function main.So instead of
int main() {
//some code here
return 0;
}you are allowed to type
int main() {
//your code
}and the compiler will happily insert the implicit return 0; so main() returns a value as it should. I know it is slightly longer as text , but it is what you should mention. I have many other examples from this book on which I could complain. Generally it is a correct book , and anyone who wants to learn C++ cannot avoid it, but although the information is there (and it is correct) it always fails to present that information in a way that will help you to remember it , or fails to aid in categorizing and summarizing the new information. I constantly feel that the only way for this book to be useful is to use it as a primary trustful source for writing my own notes (and they would be as many pages as the book !). But anyway , I am doing all the exercises , and keep reading. I plan to read on parallel the book from I.Horton, Beginning C++ (2015 edition) to get some coverage for C++14.
geodoom wrote:
the compiler lets us
The standard doesn't. Which compiler? Under which conditions?
* CALL APOGEE, SAY AARDWOLF * GCS d--- s-/++ a- C++++ U+++ P- L- E-- W++ N++ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t++ 5? X R++ tv-- b+ DI+++ D++ G e++>+++ h--- ++>+++ y+++* Weapons extension: ma- k++ F+2 X * Never pay more than 20 bucks for a computer game. * I'm a puny punmaker.
-
geodoom wrote:
the compiler lets us
The standard doesn't. Which compiler? Under which conditions?
* CALL APOGEE, SAY AARDWOLF * GCS d--- s-/++ a- C++++ U+++ P- L- E-- W++ N++ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t++ 5? X R++ tv-- b+ DI+++ D++ G e++>+++ h--- ++>+++ y+++* Weapons extension: ma- k++ F+2 X * Never pay more than 20 bucks for a computer game. * I'm a puny punmaker.
According to [this post on Stack Overflow](https://stackoverflow.com/questions/276807/return-0-implicit) the standard does say that if no return is hit in main, the effect is that of return 0;. I've not verified the quote.
98.4% of statistics are made up on the spot.
-
According to [this post on Stack Overflow](https://stackoverflow.com/questions/276807/return-0-implicit) the standard does say that if no return is hit in main, the effect is that of return 0;. I've not verified the quote.
98.4% of statistics are made up on the spot.
It seems I confused C standard with C++. Thanks.
* CALL APOGEE, SAY AARDWOLF * GCS d--- s-/++ a- C++++ U+++ P- L- E-- W++ N++ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t++ 5? X R++ tv-- b+ DI+++ D++ G e++>+++ h--- ++>+++ y+++* Weapons extension: ma- k++ F+2 X * Never pay more than 20 bucks for a computer game. * I'm a puny punmaker.
-
So I have started reading the book , and on chapter 6 Functions, 6.3 Return Types and the return statement, he says : "Return from main There is one exception to the rule that a function with a return type other than void must return a value: The main function is allowed to terminate without a return. If control reaches the end of main and there is no return, then the compiler implicitly inserts a return of 0". And I am thinking : What? Why mr. Lippman ? why do you have to express a simple idea in such a complicated way , and mention something that is on the edge of inaccuracy ? You should say : There is NO exception to the rule that a function with a return type other than void must return a value. But because we , the programmers , do not like to type things when not necessary , the compiler lets us omit typing explicitly the return 0; in function main.So instead of
int main() {
//some code here
return 0;
}you are allowed to type
int main() {
//your code
}and the compiler will happily insert the implicit return 0; so main() returns a value as it should. I know it is slightly longer as text , but it is what you should mention. I have many other examples from this book on which I could complain. Generally it is a correct book , and anyone who wants to learn C++ cannot avoid it, but although the information is there (and it is correct) it always fails to present that information in a way that will help you to remember it , or fails to aid in categorizing and summarizing the new information. I constantly feel that the only way for this book to be useful is to use it as a primary trustful source for writing my own notes (and they would be as many pages as the book !). But anyway , I am doing all the exercises , and keep reading. I plan to read on parallel the book from I.Horton, Beginning C++ (2015 edition) to get some coverage for C++14.
-
So I have started reading the book , and on chapter 6 Functions, 6.3 Return Types and the return statement, he says : "Return from main There is one exception to the rule that a function with a return type other than void must return a value: The main function is allowed to terminate without a return. If control reaches the end of main and there is no return, then the compiler implicitly inserts a return of 0". And I am thinking : What? Why mr. Lippman ? why do you have to express a simple idea in such a complicated way , and mention something that is on the edge of inaccuracy ? You should say : There is NO exception to the rule that a function with a return type other than void must return a value. But because we , the programmers , do not like to type things when not necessary , the compiler lets us omit typing explicitly the return 0; in function main.So instead of
int main() {
//some code here
return 0;
}you are allowed to type
int main() {
//your code
}and the compiler will happily insert the implicit return 0; so main() returns a value as it should. I know it is slightly longer as text , but it is what you should mention. I have many other examples from this book on which I could complain. Generally it is a correct book , and anyone who wants to learn C++ cannot avoid it, but although the information is there (and it is correct) it always fails to present that information in a way that will help you to remember it , or fails to aid in categorizing and summarizing the new information. I constantly feel that the only way for this book to be useful is to use it as a primary trustful source for writing my own notes (and they would be as many pages as the book !). But anyway , I am doing all the exercises , and keep reading. I plan to read on parallel the book from I.Horton, Beginning C++ (2015 edition) to get some coverage for C++14.
I don't understand your complaint. His verbiage is perfectly clear and discrete.