Re: Req for newbie reactions: attempted Correct C++ Tutorial
From: Alf P. Steinbach (alfps_at_start.no)
Date: 02/26/05
- Previous message: Francis Glassborow: "Re: anyone can suggest some books to me?"
- In reply to: Francis Glassborow: "Re: Req for newbie reactions: attempted Correct C++ Tutorial"
- Next in thread: Alf P. Steinbach: "Re: Req for newbie reactions: attempted Correct C++ Tutorial"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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?
- Previous message: Francis Glassborow: "Re: anyone can suggest some books to me?"
- In reply to: Francis Glassborow: "Re: Req for newbie reactions: attempted Correct C++ Tutorial"
- Next in thread: Alf P. Steinbach: "Re: Req for newbie reactions: attempted Correct C++ Tutorial"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|