Advertisement

Newbie In Need Of Help...

Started by March 01, 2002 01:39 PM
18 comments, last by Scott_U 22 years, 6 months ago
Not only is it ansi standard, it generates a compiler error under msvc.

warning C4508: ''main'' : function should return a value; ''void'' return type assumed

Also, std:: is assumed just as you say return is, so why add that? you''re critique was unproductive and inacurate.
Oh dear. I''m never quite sure how to deal with this level of ignorance. I guess I''ll just address each of the points in turn.

quote:
Original post by ZealousElixir
What''s so canonical about that? It''s called confusing to newbies.

What''s canonical about it is that it''s how any C++ programmer with knowledge of the standard would write it. I don''t believe that it''s more confusing to newbies than teaching them to write illegal code.

quote:
The STL wasn''t in existence when C++ came out, but more importantly, the (now deprecated) iostream.h is just easier to deal with than forcing namespaces and templates on them all at once when they''re first starting out.

iostreams aren''t part of the STL, but they are part of the Standard Library. iostream.h is not deprecated as it was never part of the Standard. As for namespaces and templates: namespaces are a fact of life with C++, there''s nothing at alldifficult about them; and do you see any template code in my program? It''s behind the scenes and doesn''t need to be worried about.

quote:
And if you''re going to be that picky, why say that the return statement is implied? I''m fairly certain that the ANSI standard states that the return statement is required.

You''re "fairly certain"? What is that supposed to mean? I''m 100% certain that dropping off the end of main without a return implies a "return 0" statement. It''s quite clear you don''t have a clue what the Standard says about this, so please don''t try and argue about it.

--
You see some pale bulbous eyes staring at you.
Advertisement
quote: Original post by AbsolutDew
Not only is it ansi standard, it generates a compiler error under msvc.

warning C4508: ''main'' : function should return a value; ''void'' return type assumed

It is most definitely Standard compliant, and it doesn''t generate an error. It actually generates a warning - all compilers are free to generate warnings as they see fit. However, this particular warning is one of the most infamous from MS''s compiler. It is simply misleading. Just remember, MS don''t define the C++ Standard.

quote:
Also, std:: is assumed just as you say return is, so why add that? you''re critique was unproductive and inacurate.


std namespace is *not* assumed. Who told you that?

The productivity of my "critique" is subjective. I believe it saves wasted effort to ensure that those learning the C++ language are in possession of the facts from the outset. Any other approach leads to confusion and wasted time. How many times have you heard someone ask why their program''s output isn''t appearing, only to discover they are mixing iostream and iostream.h? As for accuracy - have you ever even laid eyes on a copy of the Standard? When you do, try looking up the points which you have called me on. I know what is says, whereas you are guessing (wrongly).

--
You see some pale bulbous eyes staring at you.
:|
I simply see no reason to pick apart such a simple program, complicating what an obvious novice is already having trouble with.

It works, and pretty much every programming book (obviously where he got this program from) ive seen does not qualify the namespace (at least in the beginning). perhaps my saying it was implied was a poor choice of words; It works, however, without it.

As for ANSI standard, you''re right, i was going by what the person above me said, but, i can say there is nothing wrong with putting it there.

My point is how would you feel if you had trouble understanding arrays, and someone said you should be using linked lists to use memory more efficiently. You answered his question by suggesting the breakpoint, it would have been nice if you left it at that.

Anyways this is totally unproductive so I wont post again on it.
I completely agree that a lot of programming books teach the wrong style of coding. It''s a real shame that it''s so hard to find the good books amongst the dross. FWIW, you won''t find these sorts of basic mistakes in Accelerated C++, which is written by people who know what they are talking about. Other book reviews can be found at ACCU.

--
You see some pale bulbous eyes staring at you.
Advertisement
So I''ve been doing this wrong? Uh...I''m confused...Am I supposed to use what I get from a book, or what SabreMan said? Someond help please...
I would encourage you to ignore SaberMan''s ''purist'' comments and go with what the book teaches you. The most important thing is that you learning to program, and gaining experience doing so. The biggest mistake is not to try something. As you gain experience you will develop your own style.

Keep up the good work and ignore pompus critiques. I imagine even saberman started with ''hello world''
Thanks man. I''ve passed the hello world crap (Thank God) and now I''m actually using Input and Output and Saving. I thought C++ was going to be hard to pick up but I was pleasently surprised.
I apologise if I came across as pompous, that wasn't my intention, but I can see why you might think that. My point is that this isn't a question of individual coding style, it's a question of correctness. If someone is coding C++, then I encourage them to code correct C++ wherever feasible. I don't think that's really a "purist" attitude. I'm fully aware that there are an awful lot of learning resources which basically teach poor coding habits. Many is the occasion that I've had junior programmers come onto my team with some really bad habits, and it has taken an awful lot of effort to break those habits. I really do believe it is easier in the long run to not develop those habits in the first place.

I mentioned this before, and I'll mention it again. Accelerated C++ is a learner's book written by Koenig & Moo, who are world-class experts. Andy Koenig sits on the C++ Standard committee, so his books do not contain glaring inaccuracies. It's widely regarded as the new benchmark for C++ tutorial guides.

--
You see some pale bulbous eyes staring at you.

Edited by - SabreMan on March 2, 2002 2:30:51 PM

This topic is closed to new replies.

Advertisement