Re: Req for newbie reactions: attempted Correct C++ Tutorial

From: Alf P. Steinbach (alfps_at_start.no)
Date: 02/26/05

  • Next message: Alf P. Steinbach: "Re: anyone can suggest some books to me?"
    Date: Sat, 26 Feb 2005 15:26:05 GMT
    
    

    * Francis Glassborow:
    > In article <42207e6c$0$72824$afc38c87@news.wanadoo.nl>, Martijn Mulder
    > <i@m.?.invalid> writes
    > >But more important, when you come to the chapter 'Fun with Functions' and start
    > >explaining return types, how do you think the scrutinizing newby feels about the
    > >single one exception on the rule that all none-void functions should return a
    > >value? Do you include a paragraph to explain this special quality of main?
    >
    > Why not? After all in C++ main() isn't a function (you cannot call it,
    > it does not have an address, it isn't overloaded yet has more than one
    > signature). In C++ (though not in C) there are so many special
    > characteristics about main() that it merits a brief paragraph explaining
    > that it is the entry point to a program but lacks many of the normal
    > features of a function.

    That's a good idea, I think.

    It has to be later on, though.

    For now I've added the following to the Word document (the HTML version
    is just to much work to keep updated). And thanks to Martin for commenting on
    this. I think it's important to fix such things, to not allow wrong
    impressions to just build up -- and without feedback, one does not know.

    <quote, added text>
        There are many ways of writing this program, many variations. Some of
        them are correct, some are not. Here are some of the different variants
        you might encounter elsewhere:

        * Instead of <iostream> you might see <iostream.h>. That is Incorrect.
           With some compilers it may compile and work, with e.g. Visual C++ 7.1
           it doesn't compile.

        * Some examples will have "void main" instead of "int main". That is
           also Incorrect. It is allowed by many compilers, for historical
           reasons, but the standard only allows "int main", and nothing else.

        * Most examples will lack the line with <ostream> (the fourth physical
           line in the text). Leaving out that line is formally incorrect, but it
           doesn't really matter. The requirement for <ostream> is probably just
           a very subtle oversight in the standard, and this oversight is very
           much at odds with existing practice: in practice it's "safe" to leave
           out that line.

        * Some examples will have a line with "using namespace std;". That is a
           Dangerous habit, as we'll see in chapter 5. Don't do it.

        * Some examples will have a "return 0;" command at the end, before the
           "}". That's not required for main, which is very special (the relevant
           paragraph in the standard is §3.6.1/5). However, some very old
           compilers will incorrectly insist on having that line: if you're using
           such a compiler you should switch to a better one immediately, because
           it will be non-standard in many other respects, not allowing you to
           write standard C++.
    </quote, added text>

    Cheers, and thanks (both of you),

    - Alf

    -- 
    A: Because it messes up the order in which people normally read text.
    Q: Why is it such a bad thing?
    A: Top-posting.
    Q: What is the most annoying thing on usenet and in e-mail?
    

  • Next message: Alf P. Steinbach: "Re: anyone can suggest some books to me?"

    Relevant Pages

    • Re: Re:AMC: Whats the stink about?
      ... "We walked in, sat down, Obie came in with the twenty seven eight-by-ten ... colour glossy pictures with circles and arrows and a paragraph on the ... one explaining what each one was to be used as evidence against us." ...
      (rec.arts.tv.soaps.abc)
    • Re: Re:AMC: Whats the stink about?
      ... "We walked in, sat down, Obie came in with the twenty seven eight-by-ten ... colour glossy pictures with circles and arrows and a paragraph on the ... one explaining what each one was to be used as evidence against us." ...
      (rec.arts.tv.soaps.abc)
    • Re: Lies, Damn Lies and the RSCB Web site? A FAQ for you.
      ... instead in explaining it in a paragraph of the same size. ... Come on Gareth, don't make it so hard on yourself! ... You are right to remind me of the effort that I spent outlining the articles ...
      (uk.radio.amateur)
    • Re: Telephone grounding
      ... >> circles and arrows, and a paragraph on the back of each one, explaining ...
      (sci.electronics.basics)
    • Re: Req for newbie reactions: attempted Correct C++ Tutorial
      ... when you come to the chapter 'Fun with Functions' and start ... >explaining return types, how do you think the scrutinizing newby feels about the ... Do you include a paragraph to explain this special quality of main? ... characteristics about mainthat it merits a brief paragraph explaining ...
      (alt.comp.lang.learn.c-cpp)