 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
C Guest
|
Posted: Sun Sep 14, 2003 12:42 pm Post subject: Re: The worst 'hello world' example ever written... |
|
|
The_Sage <theeSage (AT) azrmci (DOT) net> wrote
| Quote: | Reply to article by: [email]blackmarlin (AT) asean-mail (DOT) com[/email] (C)
Date written: 12 Sep 2003 04:59:48 -0700
MsgID:<33d97ee5.0309120359.14513def (AT) posting (DOT) google.com
|
[Cross posted to comp.lang.c++ as an example of the worst
'hello world' example ever written in C++, please point out
any errors I have missed. (The original poster (The_Sage)
proposes this example is 100% correct, I submit it to the
experts for critique.)]
| Quote: | you embarass yourself everytime you open your mouth.
#include
void main() { cout << "Hello, World!" }
I have been letting this slip as I post enough errors
in my code; though I will do so no longer as this is the
third time you have repeated it without corrections. You
"embarass yourself everytime you" post this code. Here
are comments and corrections...
You wrote
#include
Wrong.
|
Not wrong, your specification is bad practice, and not the C++
idiom for the inclusion of C++ headers.
| Quote: | void // Standard says should be "int"
No it doesn't, since cout doesn't return anything.
|
The return from 'cout' is irrelevant; this is C++ not
functional programming.
gemini(300)$ cat sag.cc
#include <iostream.h>
void main(){ cout << "Hello, World!" }
gemini(301)$ g++ -Wall sag.cc
sag.cc: At global scope:
sag.cc:2: `main' must return `int'
sag.cc:2: return type for `main' changed to `int'
sag.cc: In function `int main(...)':
sag.cc:2: parse error before `}' token
gemini(302)$ g++ --version
3.0
| Quote: | main() { // ok (can omit int n, char**v )
Duh.
cout << "Hello, World!" // buffer is not flushed
No need to.
|
Yes there is, some systems will not print anything otherwise.
Do you really want the portability which is the only real
advantage of C++ in this application?
| Quote: | // no ";"
The "}" takes care of that last ";".
|
No it does not; this is C++ not Pascal. See the above gcc
error messages.
| Quote: | // no return
That's what the following is...
}
|
Are you (The_Sage) completely unable to admit even the
simplest error? We all make mistakes, but when 99% of the
people on the group are confronted with one they would just
say 'whoopsy daisy, this is what I ment...', but not you.
You could have just replied 'oops, typo' and would most
probably have been duely forgiven, but instead you constantly
paint yourself into a corner as more and more evidence
proving you are wrong comes to light, loosing all credability
in the process.
I have posted this across to 'comp.lang.c++' as the people
there know C++ much better than I. I am sure they will be
able to inform you of exactly which parts of the standard
you have broken.
C
2003/9/14
PS: I am unsure whether the C++ standard specifies the auto
generation of the 'return 0;' sequence on the main() procedure
and would appreciate clarification on this matter.
|
|
| Back to top |
|
 |
Buster Copley Guest
|
Posted: Sun Sep 14, 2003 2:41 pm Post subject: Re: The worst 'hello world' example ever written... |
|
|
C wrote:
| Quote: | The_Sage <theeSage (AT) azrmci (DOT) net> wrote
[Cross posted to comp.lang.c++ as an example of the worst
'hello world' example ever written in C++, please point out
any errors I have missed. (The original poster (The_Sage)
proposes this example is 100% correct, I submit it to the
experts for critique.)]
#include <iostream.h
void main() { cout << "Hello, World!" }
I have been letting this slip as I post enough errors
in my code; though I will do so no longer as this is the
third time you have repeated it without corrections. You
"embarass yourself everytime you" post this code. Here
are comments and corrections...
You wrote
#include
Wrong.
Not wrong, your specification is bad practice, and not the C++
idiom for the inclusion of C++ headers.
|
http://www.parashift.com/c++-faq-lite/coding-standards.html#faq-27.4
| Quote: | void // Standard says should be "int"
No it doesn't, since cout doesn't return anything.
The return from 'cout' is irrelevant; this is C++ not
functional programming.
|
http://www.parashift.com/c++-faq-lite/newbie.html#faq-29.3
cout is not a function; the name of the function which is called here is
'operator <<', and its return type is 'ostream &' (or more precisely,
'std::basic_ostream &'). This is indeed
irrelevant to the return type of 'main', which is always int.
| Quote: | gemini(300)$ cat sag.cc
#include <iostream.h
void main(){ cout << "Hello, World!" }
gemini(301)$ g++ -Wall sag.cc
sag.cc: At global scope:
sag.cc:2: `main' must return `int'
sag.cc:2: return type for `main' changed to `int'
sag.cc: In function `int main(...)':
sag.cc:2: parse error before `}' token
gemini(302)$ g++ --version
3.0
main() { // ok (can omit int n, char**v )
Duh.
|
Not OK. Main always returns int and there is no 'implicit int' in C or
in C++.
| Quote: | cout << "Hello, World!" // buffer is not flushed
No need to.
Yes there is, some systems will not print anything otherwise.
Do you really want the portability which is the only real
advantage of C++ in this application?
|
The buffer will be flushed when the cout object is destroyed. A newline
might be nice though.
| Quote: | // no ";"
The "}" takes care of that last ";".
No it does not; this is C++ not Pascal. See the above gcc
error messages.
|
That's right, C++ is not Perl and you do need the semicolon.
| Quote: | // no return
That's what the following is...
}
|
Not really; that's just a closing brace. The return is implicit. main
implicitly returns 0 (EXIT_SUCCESS) when the closing brace is reached.
[snip]
| Quote: | PS: I am unsure whether the C++ standard specifies the auto
generation of the 'return 0;' sequence on the main() procedure
and would appreciate clarification on this matter.
|
Auto generation is a funny way of looking at it, but yes, the effect is
as if there were a 'return 0;' before the closing brace.
Here's one way of doing it correctly:
#include
int main () { std::cout << "Hello, world!n"; }
Questions? Comments? Suggestions?
Regards,
Buster.
|
|
| Back to top |
|
 |
White Wolf Guest
|
Posted: Sun Sep 14, 2003 3:39 pm Post subject: Re: The worst 'hello world' example ever written... |
|
|
C wrote:
| Quote: | The_Sage <theeSage (AT) azrmci (DOT) net> wrote in message
news:<eq15mv4p3rjavv0tq6olrbegjjp6kscaj4 (AT) 4ax (DOT) com>...
Reply to article by: [email]blackmarlin (AT) asean-mail (DOT) com[/email] (C)
Date written: 12 Sep 2003 04:59:48 -0700
MsgID:<33d97ee5.0309120359.14513def (AT) posting (DOT) google.com
[Cross posted to comp.lang.c++ as an example of the worst
'hello world' example ever written in C++, please point out
any errors I have missed. (The original poster (The_Sage)
proposes this example is 100% correct, I submit it to the
experts for critique.)]
[SNIP] |
The guy is either a troll or a simpleton. Just ignore him.
--
WW aka Attila
|
|
| Back to top |
|
 |
Kevin Goodsell Guest
|
Posted: Sun Sep 14, 2003 8:01 pm Post subject: Re: The worst 'hello world' example ever written... |
|
|
C wrote:
| Quote: |
[Cross posted to comp.lang.c++ as an example of the worst
'hello world' example ever written in C++, please point out
any errors I have missed. (The original poster (The_Sage)
proposes this example is 100% correct, I submit it to the
experts for critique.)]
|
We already had a thread making fun of this code earlier this week...
| Quote: |
you embarass yourself everytime you open your mouth.
#include <iostream.h
void main() { cout << "Hello, World!" }
|
The main problems are:
* Non-standard (actually old, pre-standard) header.
longer exists in C++. The replacement is <iostream>
* Incorrect return type for main. The standard explicitly states that
main must return int. In fact, every document that has ever been
accepted as a standard for either C or C++ has required an 'int' return
type for main. Some allowed it to be implicit if the return type was
omitted. This is no longer allowed in either language.
* The output may never be seen. This is not a problem with flushing
(cout will be flushed when it is destroyed on program termination). It
is a problem with not properly terminating the line. A C++ program
should end it's output with a newline.
* Once the correct header is used, cout is placed in the std namespace,
therefore it's full name is std::cout. It can either be referred to
using this fully qualified name or the name can be brought into scope
using a 'using' statement.
* Missing semi-colon after the one and only statement in main().
(referring to <iostream.h>
| Quote: |
Not wrong, your specification is bad practice, and not the C++
idiom for the inclusion of C++ headers.
|
<iostream.h> does not exist in standard C++. It's as simple as that.
| Quote: |
void // Standard says should be "int"
No it doesn't, since cout doesn't return anything.
|
Clearly a fundamental misunderstanding of how the language works.
| Quote: | cout << "Hello, World!" // buffer is not flushed
No need to.
Yes there is, some systems will not print anything otherwise.
|
The buffer is flushed, but the output still may not be seen without a
newline.
| Quote: | The "}" takes care of that last ";".
|
Another fundamental misunderstanding about the language. Semi-colons
terminate C++ statements, they don't separate them. A semicolon after
the 'cout' statement is necessary.
The corrected code looks like this:
#include
int main() // returns int
{ std::cout << "Hello, World!n"; } // std::, newline, semicolon.
-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.
|
|
| Back to top |
|
 |
Josh Sebastian Guest
|
Posted: Sun Sep 14, 2003 8:42 pm Post subject: Re: The worst 'hello world' example ever written... |
|
|
On Sun, 14 Sep 2003 20:01:54 +0000, Kevin Goodsell wrote:
| Quote: | In fact, every document that has ever been
accepted as a standard for either C or C++ has required an 'int' return
type for main.
|
<OT>
This is not true. In C, an implementation is required to accept a program
which defines main with an int return type, but it is
implementation-defined whether (and which) other return types are
acceptable.
</OT>
| Quote: | * The output may never be seen. This is not a problem with flushing
(cout will be flushed when it is destroyed on program termination). It
is a problem with not properly terminating the line. A C++ program
should end it's output with a newline.
|
It's implementation-defined. From C99 draft n869, 7.19.2:
A text stream is an ordered sequence of characters composed into lines,
each line consisting of zero or more characters plus a terminating
new-line character. Whether the last line requires a terminating
new-line character is implementation-defined.
Josh
|
|
| Back to top |
|
 |
Kevin Goodsell Guest
|
Posted: Sun Sep 14, 2003 9:06 pm Post subject: Re: The worst 'hello world' example ever written... |
|
|
Josh Sebastian wrote:
| Quote: |
OT
This is not true. In C, an implementation is required to accept a program
which defines main with an int return type, but it is
implementation-defined whether (and which) other return types are
acceptable.
/OT
|
Yeah, that's true. Kind of a technicality though... if you expect your
code to work on a standard compiler, you still have to use 'int' as
main's return type.
| Quote: |
* The output may never be seen. This is not a problem with flushing
(cout will be flushed when it is destroyed on program termination). It
is a problem with not properly terminating the line. A C++ program
should end it's output with a newline.
It's implementation-defined. From C99 draft n869, 7.19.2:
A text stream is an ordered sequence of characters composed into lines,
each line consisting of zero or more characters plus a terminating
new-line character. Whether the last line requires a terminating
new-line character is implementation-defined.
Josh
|
2 things: 1, I'm not sure why you are referencing C99 for a C++
discussion - it may or may not be applicable. 2, that wording might be
intended as a warning not to count on the last line of your *input*
being properly terminated. I wonder if there's a more explicit statement
about terminating the last line of the standard output - I think I've
heard that there is.
I'm sure it's either undefined or implementation defined, though. In any
case, it's best to terminate output with a newline.
-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.
|
|
| Back to top |
|
 |
Josh Sebastian Guest
|
Posted: Sun Sep 14, 2003 9:41 pm Post subject: Re: The worst 'hello world' example ever written... |
|
|
On Sun, 14 Sep 2003 21:06:58 +0000, Kevin Goodsell wrote:
| Quote: | Josh Sebastian wrote:
* The output may never be seen. This is not a problem with flushing
(cout will be flushed when it is destroyed on program termination). It
is a problem with not properly terminating the line. A C++ program
should end it's output with a newline.
It's implementation-defined. From C99 draft n869, 7.19.2:
A text stream is an ordered sequence of characters composed into lines,
each line consisting of zero or more characters plus a terminating
new-line character. Whether the last line requires a terminating
new-line character is implementation-defined.
2 things: 1, I'm not sure why you are referencing C99 for a C++
discussion - it may or may not be applicable.
|
Section 7 of C90, with a few exceptions, is normative in C++98. I don't
have a copy of C90, but I assume (I know -- dangerous) that the wording is
similar.
| Quote: | 2, that wording might be
intended as a warning not to count on the last line of your *input*
being properly terminated. I wonder if there's a more explicit statement
about terminating the last line of the standard output - I think I've
heard that there is.
|
I couldn't find one, but that doesn't mean it isn't there.
| Quote: | I'm sure it's either undefined or implementation defined, though. In any
case, it's best to terminate output with a newline.
|
True.
Josh
|
|
| Back to top |
|
 |
The_Sage Guest
|
Posted: Mon Sep 15, 2003 12:45 am Post subject: Re: The worst 'hello world' example ever written... |
|
|
| Quote: | Reply to article by: [email]blackmarlin (AT) asean-mail (DOT) com[/email] (C)
Date written: 14 Sep 2003 05:42:24 -0700
MsgID:<33d97ee5.0309140442.5fae41c6 (AT) posting (DOT) google.com
[Cross posted to comp.lang.c++ as an example of the worst
'hello world' example ever written in C++, please point out
any errors I have missed. (The original poster (The_Sage)
proposes this example is 100% correct, I submit it to the
experts for critique.)]
|
Yes, and they whipped your ass too.
The Sage
=============================================================
My Home Page : http://members.cox.net/the.sage
"The men that American people admire most extravagantly are
most daring liars; the men they detest the most violently are
those who try to tell them the truth" -- H. L. Mencken
=============================================================
|
|
| Back to top |
|
 |
The_Sage Guest
|
Posted: Mon Sep 15, 2003 1:09 am Post subject: Re: The worst 'hello world' example ever written... |
|
|
| Quote: | Reply to article by: Kevin Goodsell <usenet1.spamfree.fusion (AT) neverbox (DOT) com
Date written: Sun, 14 Sep 2003 20:01:54 GMT
MsgID:
[Cross posted to comp.lang.c++ as an example of the worst
'hello world' example ever written in C++, please point out
any errors I have missed. (The original poster (The_Sage)
proposes this example is 100% correct, I submit it to the
experts for critique.)]
We already had a thread making fun of this code earlier this week...
|
As we will see, the laugh is on you...
| Quote: | you embarass yourself everytime you open your mouth.
#include
void main() { cout << "Hello, World!" }
The main problems are:
* Non-standard (actually old, pre-standard) header.
longer exists in C++. The replacement is <iostream
|
It isn't non-standard, is just isn't specified in the standard that way. It is
on your hard drive as "iostream.h" and you can use it both ways, just one way is
standard and the other is not.
| Quote: | * Incorrect return type for main. The standard explicitly states that
main must return int. In fact, every document that has ever been
accepted as a standard for either C or C++ has required an 'int' return
type for main. Some allowed it to be implicit if the return type was
omitted. This is no longer allowed in either language.
|
The C standard (ISO/IEC 9899:1999) does not require main() to return anything
although the C++ standard does. But ISO C++ Standard (ISO/IEC 14882:1998)
specifically requires main to return int although you *can* use void main() in
IBM, WATCOM, or MS C++ (as well as other) ISO compliant compilers.
http://homepages.tesco.net/~J.deBoynePollard/FGA/legality-of-void-main.html
| Quote: | * The output may never be seen. This is not a problem with flushing
(cout will be flushed when it is destroyed on program termination). It
is a problem with not properly terminating the line. A C++ program
should end it's output with a newline.
|
Obviously you are an armchair programmer since you are merely guessing. All that
will happen is this...
C:>Hello
Hello World
C:
Instead of...
C:>Hello
Hello World
C:
No guessing needed! Funny how the real world works like that, eh?
| Quote: | * Once the correct header is used, cout is placed in the std namespace,
therefore it's full name is std::cout. It can either be referred to
using this fully qualified name or the name can be brought into scope
using a 'using' statement.
|
Or you can set it in some compilers to default to namespaces by default...which
most do.
| Quote: | * Missing semi-colon after the one and only statement in main().
|
That's because it isn't required in all cases. The bracket takes care of that
one special case where it isn't required.
| Quote: | (referring to <iostream.h
Not wrong, your specification is bad practice, and not the C++
idiom for the inclusion of C++ headers.
iostream.h> does not exist in standard C++. It's as simple as that.
|
Yes it does. Just do a file search for it on your computer (presuming you have a
ISO compliant C++ compiler installed on it).
| Quote: | void // Standard says should be "int"
No it doesn't, since cout doesn't return anything.
Clearly a fundamental misunderstanding of how the language works.
|
Oh yes, "clearly". Not even close. Haha! You are so full of shit.
The Sage
=============================================================
My Home Page : http://members.cox.net/the.sage
"The men that American people admire most extravagantly are
most daring liars; the men they detest the most violently are
those who try to tell them the truth" -- H. L. Mencken
=============================================================
|
|
| Back to top |
|
 |
Kevin Goodsell Guest
|
Posted: Mon Sep 15, 2003 1:41 am Post subject: Re: The worst 'hello world' example ever written... |
|
|
The_Sage wrote:
| Quote: | Reply to article by: Kevin Goodsell <usenet1.spamfree.fusion (AT) neverbox (DOT) com
* Non-standard (actually old, pre-standard) header.
longer exists in C++. The replacement is <iostream
It isn't non-standard, is just isn't specified in the standard that way. It is
on your hard drive as "iostream.h" and you can use it both ways, just one way is
standard and the other is not.
|
My hard drive does not define what is and is not standard. Neither does
yours.
compiler it is probably not the same as <iostream>. Things have changed
since ARM C++.
| Quote: | The C standard (ISO/IEC 9899:1999) does not require main() to return anything
|
A technicality. You still can't use 'void' if you expect your code to
compile on a standard compliant compiler.
| Quote: | although the C++ standard does.
|
Yes, it does. And you used void anyway. Therefore you were wrong.
| Quote: | But ISO C++ Standard (ISO/IEC 14882:1998)
specifically requires main to return int although you *can* use void main() in
IBM, WATCOM, or MS C++ (as well as other) ISO compliant compilers.
|
Are you sure? The lack of a compiler error does not make it correct. The
standard does not require a diagnostic for an incorrect return type for
main.
Wow, you can use a search engine.
| Quote: |
* The output may never be seen. This is not a problem with flushing
(cout will be flushed when it is destroyed on program termination). It
is a problem with not properly terminating the line. A C++ program
should end it's output with a newline.
Obviously you are an armchair programmer since you are merely guessing. All that
will happen is this...
C:>Hello
Hello World
C:
Instead of...
C:>Hello
Hello World
C:
No guessing needed! Funny how the real world works like that, eh?
|
Yeah, funny. There are any number of compilers/systems out there that
won't display this output. We've seen several posts here where somebody
said "My hello world program isn't working" and the problem was actually
that they failed to properly terminate the output. It seems you are the
one that's guessing, based on very limited experience.
| Quote: |
* Once the correct header is used, cout is placed in the std namespace,
therefore it's full name is std::cout. It can either be referred to
using this fully qualified name or the name can be brought into scope
using a 'using' statement.
Or you can set it in some compilers to default to namespaces by default...which
most do.
|
That sentence doesn't even make sense.
A standard-compliant compiler must issue a diagnostic for code that
fails to properly qualify names, or bring them into scope with a 'using'
statement.
| Quote: |
* Missing semi-colon after the one and only statement in main().
That's because it isn't required in all cases.
|
It is in this case.
| Quote: | The bracket takes care of that
one special case where it isn't required.
|
I don't know what this means, but the bracket has nothing to do with
your missing semicolon. Though you may be able to find (broken)
compilers that allow 'void main' and no namespaces, I doubt you can find
any compiler that will accept the missing semicolon.
| Quote: |
iostream.h> does not exist in standard C++. It's as simple as that.
Yes it does. Just do a file search for it on your computer (presuming you have a
ISO compliant C++ compiler installed on it).
|
Again, what's on my computer has nothing to do with what is standard.
<iostream.h> is not standard.
| Quote: |
Oh yes, "clearly". Not even close. Haha! You are so full of shit.
|
Everyone here knows which of us is full of shit.
-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.
|
|
| Back to top |
|
 |
Greg Schmidt Guest
|
Posted: Mon Sep 15, 2003 1:45 am Post subject: Re: The worst 'hello world' example ever written... |
|
|
On Sun, 14 Sep 2003 18:09:49 -0700, The_Sage <theeSage (AT) azrmci (DOT) net>
wrote:
| Quote: | Reply to article by: Kevin Goodsell <usenet1.spamfree.fusion (AT) neverbox (DOT) com
Date written: Sun, 14 Sep 2003 20:01:54 GMT
MsgID:
* Non-standard (actually old, pre-standard) header.
longer exists in C++. The replacement is <iostream
It isn't non-standard, is just isn't specified in the standard that way. It is
on your hard drive as "iostream.h" and you can use it both ways, just one way is
standard and the other is not.
|
Okay, so one way is not standard, but that doesn't make it non-standard?
What kind of logic is that?
The standard does not preclude a compiler manufacturer from including
extra non-standard header files with their distribution. An example you
might know would be windows.h Such inclusion does not make them
standard.
This is what's known as a "non-standard extension". Just because IBM
and MS support it doesn't make it standard.
| Quote: | * The output may never be seen. This is not a problem with flushing
(cout will be flushed when it is destroyed on program termination). It
is a problem with not properly terminating the line. A C++ program
should end it's output with a newline.
Obviously you are an armchair programmer since you are merely guessing. All that
will happen is this...
C:>Hello
Hello World
C:
Instead of...
C:>Hello
Hello World
C:
|
What's this C: thing? My prompt looks like this:
(gregs) $
Have you ever tried any UNIX compilers, or are you merely guessing that
they will exhibit similar properties to Windows compilers? Here's what
it might look like if I ran that same app here:
(gregs) $ hello
Hello World(gregs) $
or maybe like this:
(gregs) $ hello
(gregs) $
Here's something else it might look like:
(gregs) $ hello
Segmentation fault, core dumped.
(gregs) $
| Quote: | No guessing needed! Funny how the real world works like that, eh?
|
Funny how the portion of the real world with which you are familiar is
like that. Funny how you believe that the entire real world is the same
as your experiences. Funny how long it might take you to track down
this bug when you port to a compiler which you are not familiar with,
and which implements "implementation defined" behaviour differently from
what you expect. Well, funny for us; not so funny for the guy that pays
you for the time it takes you to debug your port. The guess involved is
the one where you guess that other compilers (including future versions
of compiler X) work just like compiler X.
| Quote: | * Once the correct header is used, cout is placed in the std namespace,
therefore it's full name is std::cout. It can either be referred to
using this fully qualified name or the name can be brought into scope
using a 'using' statement.
Or you can set it in some compilers to default to namespaces by default...which
most do.
|
What does "default to namespaces by default" mean?
| Quote: | * Missing semi-colon after the one and only statement in main().
That's because it isn't required in all cases. The bracket takes care of that
one special case where it isn't required.
|
As others have said here, it is in fact required by the standard. If
your compiler doesn't require it, then that's another non-standard
extension that you would be well advised not to rely on.
| Quote: | iostream.h> does not exist in standard C++. It's as simple as that.
Yes it does. Just do a file search for it on your computer (presuming you have a
ISO compliant C++ compiler installed on it).
|
Hey, I found a file on my computer called TheSageIsABigIdiot.wiffle.blat
I guess it must be a part of standard C++, since I have an ISO compliant
C++ compiler installed. What's that, you say the file wasn't put there
by installing the compiler? Okay then, how about this other file called
g++ which was installed with the compiler, is that part of standard C++?
| Quote: | void // Standard says should be "int"
No it doesn't, since cout doesn't return anything.
Clearly a fundamental misunderstanding of how the language works.
Oh yes, "clearly". Not even close. Haha! You are so full of shit.
|
cout isn't a function, it's an object. Objects don't return anything,
only functions do. And, as pointed out elsewhere, the function in
question ("<<") does return something. And the original comment was
with respect to the return value of main, which has absolutely nothing
to do with the return value of "<<". Seems pretty clear to me that
whoever wrote the "No it doesn't" line has demonstrated a fundamental
misunderstanding of at least 3 facets of the language, all in a single
sentence. If you don't see this, then you are also suffering from the
same misunderstanding.
| Quote: | "The men that American people admire most extravagantly are
most daring liars; the men they detest the most violently are
those who try to tell them the truth" -- H. L. Mencken
|
A-ha! I understand now! Sage is trying to become someone that American
people admire most extravagantly! He is afraid that if he posts factual
information or agrees with obvious truths he will become most violently
detested. Let me assure you, Sage, Mr. Mencken was not referring to
technical newsgroups when he made that statement.
--
Greg Schmidt (gregs (AT) trawna (DOT) com)
Trawna Publications (http://www.trawna.com/)
|
|
| Back to top |
|
 |
Jonathan Mcdougall Guest
|
Posted: Mon Sep 15, 2003 3:32 am Post subject: Re: The worst 'hello world' example ever written... |
|
|
| Quote: | you embarass yourself everytime you open your mouth.
#include <iostream.h
void main() { cout << "Hello, World!" }
The main problems are:
* Non-standard (actually old, pre-standard) header.
longer exists in C++. The replacement is <iostream
It isn't non-standard, is just isn't specified in the standard that way. It is
on your hard drive as "iostream.h" and you can use it both ways, just one way is
standard and the other is not.
|
We discuss standard C++ here. If you have some problems with a
specific implementation, please take the discussion to its dedicated
newgroup.
| Quote: | * Incorrect return type for main. The standard explicitly states that
main must return int. In fact, every document that has ever been
accepted as a standard for either C or C++ has required an 'int' return
type for main. Some allowed it to be implicit if the return type was
omitted. This is no longer allowed in either language.
The C standard (ISO/IEC 9899:1999) does not require main() to return anything
although the C++ standard does.
|
In both standards, main() is required to return int. Please, try to
be informed before posting such false statements.
This is not a standard behavior and this newsgroup only discusses
standard C++. If you have some problems with a specific
implementation, please take the discussion to its dedicated newgroup.
| Quote: | * The output may never be seen. This is not a problem with flushing
(cout will be flushed when it is destroyed on program termination). It
is a problem with not properly terminating the line. A C++ program
should end it's output with a newline.
Obviously you are an armchair programmer since you are merely guessing. All that
will happen is this...
C:>Hello
Hello World
C:
Instead of...
C:>Hello
Hello World
C:
No guessing needed! Funny how the real world works like that, eh?
|
We do not discuss the real world, we discuss standard C++. On one of
the implementations I work on, nothing is displayed since there is no
screen.
Standard C++ does not force implementations to flush the buffer when
std::cout is destroyed. If you have some problems with a specific
implementation, please take the discussion to its dedicated newgroup.
| Quote: | * Once the correct header is used, cout is placed in the std namespace,
therefore it's full name is std::cout. It can either be referred to
using this fully qualified name or the name can be brought into scope
using a 'using' statement.
Or you can set it in some compilers to default to namespaces by default...which
most do.
|
Implementation-defined behaviors are not discussed here. If you have
some problems with a specific implementation, please take the
discussion to its dedicated newgroup.
| Quote: | * Missing semi-colon after the one and only statement in main().
That's because it isn't required in all cases. The bracket takes care of that
one special case where it isn't required.
|
Wrong. Please try to get informed before posting such false
statements.
| Quote: | (referring to <iostream.h
Not wrong, your specification is bad practice, and not the C++
idiom for the inclusion of C++ headers.
iostream.h> does not exist in standard C++. It's as simple as that.
Yes it does. Just do a file search for it on your computer (presuming you have a
ISO compliant C++ compiler installed on it).
|
Minesweeper also exists on my computer, yet it is not standard C++.
Just because a header is shipped with a compiler does not mean it is
standard.
| Quote: | void // Standard says should be "int"
No it doesn't, since cout doesn't return anything.
Clearly a fundamental misunderstanding of how the language works.
Oh yes, "clearly". Not even close. Haha! You are so full of shit.
|
Please try to respect other posters, as we try to respect you.
What point are you trying to make here? You definitly know you are
wrong. Either you are a troll or you have some serious problems with
your keyboard.
Jonathan
|
|
| Back to top |
|
 |
C Guest
|
Posted: Mon Sep 15, 2003 10:48 pm Post subject: Re: The worst 'hello world' example ever written... |
|
|
Buster Copley <buster (AT) none (DOT) com> wrote
| Quote: | C wrote:
The_Sage <theeSage (AT) azrmci (DOT) net> wrote
|
[snip]
| Quote: | main() { // ok (can omit int n, char**v )
Duh.
Not OK. Main always returns int and there is no 'implicit int' in C or
in C++.
|
My original post (on alt.lang.asm) had the quoted example
on contigious lines, it got a little split up in the reply.
You are, never the less, entirely correct in your assertion.
[snip]
| Quote: | // no return
That's what the following is...
}
Not really; that's just a closing brace. The return is implicit.
main implicitly returns 0 (EXIT_SUCCESS) when the closing brace
is reached.
|
I must admit to being rather surprised that a return with a value
can be implied, is this just for the main() procedure or does it
apply to all functions and if the latter, surely it would be good
practice to write the return anyway?
[snip]
| Quote: | Here's one way of doing it correctly:
#include
int main () { std::cout << "Hello, world!n"; }
|
Ah! My counter example was almost correct (I do not think it made
it to comp.lang.c++ : see alt.lang.asm if you are interested), not
bad for someone who has neither a C++ compiler (at the time of
writing) or any knowledge of the C++ standard. :-)
Anyway I will probably take the time to learn C++ properly (no
need to ask the opinions of all at comp.lang.c++ -- I am sure you
all think that a good idea), to that end your FAQ is comming in
very handy. Thanks.
C
2003/9/15
|
|
| Back to top |
|
 |
C Guest
|
Posted: Mon Sep 15, 2003 11:10 pm Post subject: Re: The worst 'hello world' example ever written... |
|
|
"White Wolf" <wolof (AT) freemail (DOT) hu> wrote
[snip]
| Quote: | The guy is either a troll or a simpleton. Just ignore him.
|
I wish that where possible, the arguments he (TSag) posts to
alt.lang.asm are totally against assembly programming and
founded on misconceptions which have not been true for years.
Sadly his arguments have just enough of a veneer of accuracy
that they cannot be simply ignored and must be confronted
else non experts in the field may be mislead -- the results
of proving him wrong you have seen in this thread.
So troll, yes, probably, but turning a blind eye is not an
option if new programmers are to be pursuaded that learning
the assembly paradigm is a good idea. Thanks for the reply
anyway.
C
2003/9/15
PS: Hopefully he will either go and pester another group, or
preferably, quite down, learn the subject properly, and become
a helpful member of the group.
PPS: Sorry for swinging rather offtopic for comp.lang.c++,
an explaination seemed in order -- pop over to alt.lang.asm
to see what has been happening for the last few months for a
better picture. [Please direct any follow ups to this post
there.]
|
|
| Back to top |
|
 |
Kevin Goodsell Guest
|
Posted: Tue Sep 16, 2003 1:10 am Post subject: Re: The worst 'hello world' example ever written... |
|
|
C wrote:
| Quote: |
I must admit to being rather surprised that a return with a value
can be implied, is this just for the main() procedure or does it
apply to all functions and if the latter, surely it would be good
practice to write the return anyway?
|
It only applies to main. A similar rule was adopted into the C language
with the C99 major update.
-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|