Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. The C++ primer 5th Edition (by Lippman ), an example of bad way to express something.

The C++ primer 5th Edition (by Lippman ), an example of bad way to express something.

Scheduled Pinned Locked Moved The Weird and The Wonderful
c++helptutorialquestionlearning
6 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    geodoom
    wrote on last edited by
    #1

    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.

    D M M 3 Replies Last reply
    0
    • G geodoom

      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.

      D Offline
      D Offline
      den2k88
      wrote on last edited by
      #2

      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.

      P 1 Reply Last reply
      0
      • D den2k88

        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.

        P Offline
        P Offline
        PeejayAdams
        wrote on last edited by
        #3

        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.

        D 1 Reply Last reply
        0
        • P PeejayAdams

          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.

          D Offline
          D Offline
          den2k88
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • G geodoom

            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.

            M Offline
            M Offline
            megaadam
            wrote on last edited by
            #5

            :cool:15 years ago I tried to read a book by him, but I fell asleep when I got to: "Lippma

            ... such stuff as dreams are made on

            1 Reply Last reply
            0
            • G geodoom

              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.

              M Offline
              M Offline
              madwilliamflint
              wrote on last edited by
              #6

              I don't understand your complaint. His verbiage is perfectly clear and discrete.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups