Re: The worst 'hello world' example ever written...

G

Greg Schmidt

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.

Some folks here may be interested to hear that I installed MS VS7.1
today, and iostream.h is *not* part of the installation. I found out
when I tried to compile some code (not mine) which used it, and failed.
TheSage will likely insist that my computer is in some parallel universe
or that I did something non-standard with my installation, but I assure
you that neither of these are true. Looks like MS VS7.1 is quite a bit
more standard-compliant (in this and other ways) than anything we've
seen from them before. Maybe I'll try the code that was posted and see
what output results...
 
A

Andrew Koenig

C> I must admit to being rather surprised that a return with a value
C> can be implied, is this just for the main() procedure or does it
C> apply to all functions and if the latter, surely it would be good
C> practice to write the return anyway?

It's just for main, and it's a backward compatibility hack.
It's good practice to write the return anyway.
 
A

Andrew Koenig

My hard drive does not define what is and is not standard. Neither does
TS> Whether it is a standard or not, it is acceptable. IBM, MS, and
TS> Borland all agree with my interpretation of the standard and not
TS> yours.

Your interpretation of the standard is incorrect. Here is what the
standard actually says:

Subclause 3.6.1, paragraph 2:

An implementation shall not predefine the `main' function.
This function shall not be overloaded. It shall have a return
type of type `int,' but otherwise its type is implementation-
defined. All implementations shall allow both of the following
definitions of `main':

int main() { /* ... */ }

and

int main(int argc, char* argv[]) { /* ... */ }

When the C++ standard uses the word ``shall'' in this way, it
expresses a requirement on programs that every standard-conforming
implementation is required to enforce, at least by producing a
diagnostic message (which might be only a warning) for any program
that does not meet the requirement.

So, for example, if I try to compile the following program:

void main() { }

under g++ version 3.3.1, I get the following message:

prog.c:1: error: `main' must return `int'

That's what the standard says should happen.

In practice, many compilers allow `main' to return void. This
practice is not sanctioned by the standard, but probably does reduce
the number of complaints from users who have read books that
incorrectly claim that `main' is permitted to return void. Strictly
speaking, a compiler that permits `main' to return void does not
conform to the standard, and a customer that requires the compilers
they use to conform to the standard would be justified in rejecting
the compiler on those grounds.

In summary, if you tell me that `main' is permitted to return void
because the compilers you use happen to accept it, my response is:

1) The compiler I use doesn't accept it.

2) The C++ standard clearly says it's wrong.

3) Your compilers are not conforming to the standard.




Regards,


Andrew Koenig
 
T

The_Sage

Reply to article by: Josh Sebastian said:
Date written: Mon, 15 Sep 2003 22:53:14 -0400
MsgID:<[email protected]>
You have not "interpreted" the standard, you have chosen to ignore
it. Those compilers also compile C code. That doesn't mean that valid C is
always valid C++. Your logic is faulty.
The reason it works is because they didn't want to break old code.

No, that isn't the reason because neither IBM, MS, nor Borland give that as a
reason. They all state that their compiler is ISO compliant and they all agree
with my interpretation and disagree with yours.

Case closed.

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
=============================================================
 
T

The_Sage

Reply to article by: Andrew Koenig said:
Date written: Tue, 16 Sep 2003 14:40:02 GMT
MsgID:<[email protected]>
TS>Whether it is a standard or not, it is acceptable. IBM, MS, and
TS>Borland all agree with my interpretation of the standard and not
TS>yours.
Your interpretation of the standard is incorrect.

You mean, IBM, MS, Borland and other compiler manufacturer's interpretation of
the standard is incorrect.
Here is what the standard actually says:
Subclause 3.6.1, paragraph 2:
An implementation shall not predefine the `main' function.
This function shall not be overloaded. It shall have a return
type of type `int,' but otherwise its type is implementation-
defined. All implementations shall allow both of the following
definitions of `main':
int main() { /* ... */ }

int main(int argc, char* argv[]) { /* ... */ }
When the C++ standard uses the word ``shall'' in this way, it
expresses a requirement on programs that every standard-conforming
implementation is required to enforce, at least by producing a
diagnostic message (which might be only a warning) for any program
that does not meet the requirement.
So, for example, if I try to compile the following program:
void main() { }
under g++ version 3.3.1, I get the following message:
prog.c:1: error: `main' must return `int'
That's what the standard says should happen.

The standard does not mention any error messages when using a different version
of main(). What the standard actually implies, and I quote research at ATT
concerning this topic...

"A conforming implementation accepts
int main() { /* ... */ }

and

int main(int argc, char* argv[]) { /* ... */ }

A conforming implementation may provide more versions of main(),
but they must all have return type int"
(http://www.research.att.com/~bs/bs_faq2.html#void-main)
In practice, many compilers allow `main' to return void. This
practice is not sanctioned by the standard, but probably does reduce
the number of complaints from users who have read books that
incorrectly claim that `main' is permitted to return void.

On most of the major compilers, it is permitted, so the books are correct.
Strictly
speaking, a compiler that permits `main' to return void does not
conform to the standard, and a customer that requires the compilers
they use to conform to the standard would be justified in rejecting
the compiler on those grounds.

Strictly speaking, it is conforming, it just isn't recommended because it may
not be portable, for example, GCC doesn't implement any other version of main()
other than the one suggested by the ISO standard.
In summary, if you tell me that `main' is permitted to return void
because the compilers you use happen to accept it, my response is:
1) The compiler I use doesn't accept it.

That proves nothing, as explained above.
2) The C++ standard clearly says it's wrong.

No it doesn't.
3) Your compilers are not conforming to the standard.

Yes they are.

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
=============================================================
 
N

Noah Roberts

The_Sage said:
The standard does not mention any error messages when using a different version
of main(). What the standard actually implies, and I quote research at ATT
concerning this topic...

"A conforming implementation accepts
int main() { /* ... */ }

and

int main(int argc, char* argv[]) { /* ... */ }

A conforming implementation may provide more versions of main(),
but they must all have return type int"

You are really bad at this aren't you...

In case you don't realize...this is exactly what everyone has been
trying to tell you. main() must return type int. You have just proven
yourself wrong :p

NR
 
J

Josh Sebastian

No, that isn't the reason because neither IBM, MS, nor Borland give that as a
reason. They all state that their compiler is ISO compliant

No, they don't. They each list specific points where their compiler
is not compliant. Off the top of my head, none of them supports the export
keyword. Borland gave their implementation of the Standard Library less
than a 92% compliance rating:
http://bdn.borland.com/article/0,1410,29080,00.html
and they all agree
with my interpretation and disagree with yours.

They state their compilers are ISO compliant /with extensions/. A compiler
that was simply ISO compliant and nothing more wouldn't be very useful.
"With extensions" means that the compiler allows you to do things that the
rules of C++ do not allow. For example, the C++ rules for the
main() function can be found here:
http://oscinfo.osc.edu/software/docs/kaic/ANSI-Dec-1996/basic.html

Now, compare that to the MS Visual C++ rules for the main() function,
which can be found here:
http://msdn.microsoft.com/library/d...ang_program_startup.3a_.the_main_function.asp

Do you see the differences? Do you see how MS's rules are slightly
different than the Standard's rules? Just because you follow MS's rules
(and it compiles with MS's compiler) does not mean you've followed all the
rules of the Standard.

Josh
 
J

Josh Sebastian

You mean, IBM, MS, Borland and other compiler manufacturer's interpretation of
the standard is incorrect.

No. We're saying that IBM, MS, and Borland know that their compilers are
not perfectly compliant, and (for many conformance issues) they don't
care.
 
T

T.M. Sommers

The_Sage said:
Reply to article by: Andrew Koenig <[email protected]>
Date written: Tue, 16 Sep 2003 14:40:02 GMT
MsgID:<[email protected]>

The standard does not mention any error messages when using a different version
of main(). What the standard actually implies, and I quote research at ATT
concerning this topic...

"A conforming implementation accepts
int main() { /* ... */ }

and

int main(int argc, char* argv[]) { /* ... */ }

A conforming implementation may provide more versions of main(),
but they must all have return type int"
(http://www.research.att.com/~bs/bs_faq2.html#void-main)

Did you read the two sentences before the one you quote? If not, here
they are:

The definition

void main() { /* ... */ }

is not and never has been C++, nor has it even been C. See
the ISO C++ standard 3.6.1[2] or the ISO C standard 5.1.2.2.1.
That proves nothing, as explained above.


No it doesn't.


Yes they are.

You do realize, don't you, that the Mr. Koenig you are contradicting
above is the project editor of the C++ standards committee?
 
R

Randall Hyde

T.M. Sommers said:
The_Sage wrote:

You do realize, don't you, that the Mr. Koenig you are contradicting
above is the project editor of the C++ standards committee?

What are you C++ guys complaining about?
Mr. "The_Sage" cannot even differentiate assembly code and C code
(he insists that an assembly language file I uploaded a while back was
a C file and continues to claim that I am "lying" when I claim otherwise).

Seriously, though, we all need to cut Mr. "The_Sage" some slack here.
He is clearly in need of some serious help and the continuous negative
feedback we are giving him is just causing him to sink deeper and deeper
into the depths of mental illness (specfically, ignoring reality, as acknowledging
reality would require him to admit that he is wrong, something he very *rarely*
does).

We should all take pity on him and just ignore him.
Cheers,
Randy Hyde
 
J

Jerry Coffin

[ ... ]
You mean, IBM, MS, Borland and other compiler manufacturer's interpretation of
the standard is incorrect.

That's not the correct conclusion at all. To quote from section 1.4/8
of the standard:

A conforming implementation may have extensions (including
additional library functions), provided they do not alter
the behavior of any well-formed program. Implementations
are required to diagnose programs that use such extensions
that are ill-formed according to this international standard.
Having done so, they can compile and execute such programs.

In addition to that, most compilers require very specific usage to run
in their (most) conforming mode. In other modes, they may (for example)
accept programs that are ill-formed according to the standard, without
any diagnostics at all.

In short, the fact that you've used a couple of compilers and they
accept the code means precisely and exactly NOTHING about whether your
code is correct.

[ ... ]
The standard does not mention any error messages when using a different version
of main().

Quite the contrary -- you simply have to learn how to read the standard
as a whole instead of ignoring the parts that don't suit what you'd like
to believe.
What the standard actually implies, and I quote research at ATT
concerning this topic...

The standard does not imply -- it states quite specifically that at
least one diagnostic is required for any program that violates a
syntactic rule or a diagnosable semantic rule of the standard.

[ ... ]
On most of the major compilers, it is permitted, so the books are correct.

That depends on whether the books purport to teach C++, or "whatever
most major compilers accept".

[ ... ]
No it doesn't.

Yes, it most assuredly does.
Yes they are.

Regardless of this particular part, they most assuredly are NOT. I'm
reasonably certain that there is only one C++ compiler today that can
honestly make ANY claim to conforming with the standard (and that's from
Comeau). Every other C++ compiler around has well-known and major
omissions in its implementation of C++. You've listed IBM, MS and
Borland above as your compilers, and here you're claiming that they
conform. If you look at:

http://msdn.microsoft.com/chats/vstudio/vstudio_022703.asp

You'll find a rather lengthy interview, in which a number of MS
employees openly state that MS' current compiler is NOT a conforming
implementation of C++.

At:

http://ww6.borland.com/plumhall/phq.exe/ShowTable

You'll find Borland's own statement that their most recent compiler is
NOT a conforming implementation of C++. From their viewpoint, it's a
good thing that their compiler passes almost 92% of the tests in the
Plum-Hall validation suite (and I tend to agree that this is quite
good). From any viewpoint, however, 92% is not the same as 100% -- a
100% is the point at which you can start to argue that it MIGHT be a
conforming implementation. Anything less than 100% means that they know
full-well that the implementation doesn't conform.
 
D

David B. Held

The_Sage said:
[...]
You mean, IBM, MS, Borland and other compiler
manufacturer's interpretation of the standard is incorrect.

Given the way you "interpret" standards, I must conclude that
you are not a programmer, and that any well-formed programs
that you do write must be the result of a mind-bogglingly
improbably accident comparable to a thousand monkeys
randomly producing the entire works of Shakespeare on
typewriters.
Strictly speaking, it is conforming, it just isn't recommended

What isn't recommended is you going near a C++ compiler.
because it may not be portable,

Someone who defies the standard itself, and then quotes the
draft standard as support, and then continues arguing that
"void main()" is legal C++ is utterly unqualified to speak an
iota about portability.
for example, GCC doesn't implement any other version of
main() other than the one suggested by the ISO standard.

All the other forms of main() allowed by the ISO standard
have a return type of int.
[...]
2) The C++ standard clearly says it's wrong.

No it doesn't.

Ok, so here we have it:

1) C++ Standard, specifying the return type of main()
2) interpreters of the standard, who disagree on 1)

One of the interpreters is a C++ committee member, an
author of an acclaimed C++ book, an internationally
recognized C++ expert, and has a language feature named
after him. The other signs his posts with an alias (unless
"The Sage" is his/her legal name), has no known publications,
is an internationally recognized crank, and wouldn't be
allowed on the C++ committee if he paid everyone else's
dues. I wonder which one is more qualified to determine
whether the standard allows main() to return void? This
is a difficult and vexing question...hmm...
Yes they are.

And that, of course, is because "conforming" means "what
my compiler does". Which is why we write standards. To
describe what compilers *do*, not what they are
*supposed* to do. I see. It all makes sense. Anyone
else want a hit on the bong?

Now, I have a proof that this crackpot is none other than
the convener of the C++ committe himself! See, the casual
reader would assume that "sage" means "wise". But it doesn't
take a rocket scientist to see that no wisdom can be found in
the words of this poster, which means we are forced to
conclude that "sage" means "herb"...hmm..."The herb"...
which might explain the inspiration for his ideas, but is a
tangential issue at best. No, there is only *one* "herb"
when it comes to C++, and that's "herb" Sutter! He's just
yanking everyone's chain and having a laugh at our expense!
[...]
"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

I really admire the way you defend your position. Oh, and
"audacious" != "brave bearer of truth". After all, fools rush in
where angels fear to tread.

Dave
 
T

The_Sage

Reply to article by: Noah Roberts said:
Date written: Tue, 16 Sep 2003 18:38:43 -0700
MsgID:<[email protected]>
"A conforming implementation accepts
int main() { /* ... */ }
and
int main(int argc, char* argv[]) { /* ... */ }
A conforming implementation may provide more versions of main(),
but they must all have return type int"
You are really bad at this aren't you...
In case you don't realize...this is exactly what everyone has been
trying to tell you. main() must return type int. You have just proven
yourself wrong :p

The standard says you must return int, which all ISO compliant compilers do, BUT
IT ALSO STATES YOU CAN RETURN OTHER THINGS AS WELL. You just proved you are
illiterate.

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
=============================================================
 
T

The_Sage

Reply to article by: Josh Sebastian said:
Date written: Tue, 16 Sep 2003 22:09:45 -0400
MsgID:<[email protected]>
No. We're saying that IBM, MS, and Borland know that their compilers are
not perfectly compliant, and (for many conformance issues) they don't
care.

Quotes please, that way we can see if you are making this all up as you go along
just so you can win an argument, or if IBM, MS, and Borland are all on the
record as saying, "Yes, we violated the ISO standard but we don't care, we are
going to call it ISO compliant anyway". I await your proof.

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
=============================================================
 
T

The_Sage

Reply to article by: "T.M. Sommers said:
Date written: Wed, 17 Sep 2003 02:53:47 GMT
MsgID:<%[email protected]>
The standard does not mention any error messages when using a different version
of main(). What the standard actually implies, and I quote research at ATT
concerning this topic...
"A conforming implementation accepts
int main() { /* ... */ }
and
int main(int argc, char* argv[]) { /* ... */ }
A conforming implementation may provide more versions of main(),
but they must all have return type int"
(http://www.research.att.com/~bs/bs_faq2.html#void-main)
Did you read the two sentences before the one you quote? If not, here
they are:
The definition
void main() { /* ... */ }
is not and never has been C++, nor has it even been C. See
the ISO C++ standard 3.6.1[2] or the ISO C standard 5.1.2.2.1.

And did you stop there are did you continue on to where it amended that
statement with:

A conforming implementation may provide more versions of main(), but they must
all have return type int.

In case you can't read, it means that void main() was never specified but it can
be if you so choose to do so, just so long as you always have int main() as one
of your implementations.

It is plain and simple:

1) void main() is not defined by the ISO standard but
2) void main() is compliant

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
=============================================================
 
T

The_Sage

Reply to article by: Jerry Coffin said:
Date written: Wed, 17 Sep 2003 05:46:45 GMT
MsgID:<[email protected]>
That's not the correct conclusion at all. To quote from section 1.4/8
of the standard:
A conforming implementation may have extensions (including
additional library functions), provided they do not alter
the behavior of any well-formed program. Implementations
are required to diagnose programs that use such extensions
that are ill-formed according to this international standard.
Having done so, they can compile and execute such programs.

Using void main() does not alter the behavior of any well-formed program and the
compilers all have debuggers which recognize void main() as ISO compliant and
well-formed.
In addition to that, most compilers require very specific usage to run
in their (most) conforming mode. In other modes, they may (for example)
accept programs that are ill-formed according to the standard, without
any diagnostics at all.
In short, the fact that you've used a couple of compilers and they
accept the code means precisely and exactly NOTHING about whether your
code is correct.

We aren't talking about whether the code is correct here, but whether it is ISO
compliant.

Try again.

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
=============================================================
 
S

Sam Holden

And did you stop there are did you continue on to where it amended that
statement with:

A conforming implementation may provide more versions of main(), but they must
all have return type int.

In case you can't read, it means that void main() was never specified but it can
be if you so choose to do so, just so long as you always have int main() as one
of your implementations.

It is plain and simple:

1) void main() is not defined by the ISO standard but
2) void main() is compliant

Do you know the meaning of the words "all" and "must"?

"they must all have return type int" means exactly what it says.

It doesn't mean one must have return type int, or some must have return
type int. It means *all* must have return type it.

It doesn't mean all may have return type int, it means all *must* have
return type int.

Not being able to code a "hello world" program I can understand. Many
people have trouble with such things. However, the words "all" and
"must" are understood by most (I would have said all, but you would have
been a counter example) three year olds.
 
T

The_Sage

Reply to article by: "David B. Held said:
Date written: Wed, 17 Sep 2003 02:48:29 -0500
MsgID:<[email protected]>
Given the way you "interpret" standards, I must conclude that
you are not a programmer, and that any well-formed programs
that you do write must be the result of a mind-bogglingly
improbably accident comparable to a thousand monkeys
randomly producing the entire works of Shakespeare on
typewriters.

Given the way you cannot support anything you claim with facts or references or
logic, I must conclude you are a total idiot.

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
=============================================================
 
R

Randall Hyde

Sam Holden said:
Do you know the meaning of the words "all" and "must"?
No. He doesn't.
I've constantly pointed out to Mr. "The_Sage" that he doesn't
know the difference between a universal quantifier and an
existential quantifier (you missed the whole discussion where
he insisted that everyone else's arguments suffered from
"logical fallacies" and I quickly pointed out the logical fallacies
of his own arguments).

Bottom line, he just loves to argue. Doesn't matter whether
he's right or wrong. No, I take that back, it's much better
if he's wrong 'cause that gets even more people all worked
up over his ridiculous statements.
Randy Hyde

Cute comic about trolls:
http://www.pvponline.com/archive.php3?archive=20030915
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top