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

A

Alexander Terekhov

Attila Feher wrote:
[...]
I do not recall the C++ Standard to contain anything about threads.

Fire a search on "thread" in the C++ Std. ;-)

[...]
makes sense main would return an std::string - as an extension. But I doubt
to see how could that be implemented or required to be implemented on every
platform. Since as you have said main could return anything.

http://groups.google.com/[email protected]
(Subject: Re: Why int main()?)

#include <cthread> // that's WG21-"controlled" <pthread.h>-"copy" ;-)
#include <iostream>
using namespace std;

extern "C" void * f(void * p) {
void * result;
pthread_t * pmain_tid = (pthread_t *)p;
pthread_cancel(*pmain_tid);
pthread_join(*pmain_tid, &result);
delete pmain_tid;
const char * msg = PTHREAD_CANCELED == result ?
"canceled" : (const char *)result;
cout << msg << endl;
return 0;
}

int main() {
pthread_t * pmain_tid = new pthread_t(pthread_self()), tid;
pthread_create(&tid, 0, &f, pmain_tid);
pthread_testcancel();
pthread_exit((void*)"hello world");
}

http://groups.google.com/[email protected]
(Subject: Re: Why int main()?)

#include <thread>
#include <string>
#include <iostream>

typedef std::joinable_thread_ptr<std::string> main_thread_ptr;

void f(main_thread_ptr mtp) {
main_thread_ptr::join_t result = mtp->cancel().join();
const char * msg = std::thread_canceled(result) ?
"canceled" : result->c_str();
std::cout << msg << std::endl;
}

std::string main() {
std::new_thread(&f, main_thread_ptr(std::thread_self()));
std::thread_testcancel();
std::thread_exit(std::string("hello world"));
// Never reach here
return "";
}

regards,
alexander.
 
N

Noah Roberts

Alexander said:
Return value (of whatever type) or lack thereof (think of thread cancel)
is meant to be meaningful ONLY for joining thread(s) within program, if
any.

I realize that many people may not be using *nix systems here and so are
not wholely familiar with the roots of C (and thus C++). Returning a
value is not only important to the system, but can be important to the
user as well. For instance:


if test `program` = 23; then
diagnostics for error 23;
fi

It is also important, in many cases, to compare the return value of a
program with 0.

Of course the syntax is probably wrong but the point is that even if it
is not a useful value on your particular system (and of course you can't
really know this unless you wrote the OS) it is still important on other
systems and to users of many systems.

NR
 
A

Alexander Terekhov

Noah Roberts wrote:
[...]
Of course the syntax is probably wrong but the point is that even if it
is not a useful value on your particular system (and of course you can't
really know this unless you wrote the OS) it is still important on other
systems and to users of many systems.

Process exit status has really nothing to do with main() function
[that I'm talking about] return value/type.

regards,
alexander.
 
W

WW

Alexander said:
Noah Roberts wrote:
[...]
Of course the syntax is probably wrong but the point is that even if
it is not a useful value on your particular system (and of course
you can't really know this unless you wrote the OS) it is still
important on other systems and to users of many systems.

Process exit status has really nothing to do with main() function
[that I'm talking about] return value/type.

Did you care to read the Standard? It has everything to do with it.
 
R

Ron Natalie

Alexander Terekhov said:
Noah Roberts wrote:
[...]
Of course the syntax is probably wrong but the point is that even if it
is not a useful value on your particular system (and of course you can't
really know this unless you wrote the OS) it is still important on other
systems and to users of many systems.

Process exit status has really nothing to do with main() function
[that I'm talking about] return value/type.
Depends on the implementation.
 
A

Alexander Terekhov

WW wrote:
[...]
Process exit status has really nothing to do with main() function
[that I'm talking about] return value/type.

Did you care to read the Standard?

With respect to main(), it's totally "outdated" and poorly thought out
stuff. Never wanted to reread it. ;-)

regards,
aleandder.
 
W

WW

C wrote:
[SNIP]
[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.)]

I have finally found out what the Sage abbreviation stands for: Seriously
Abnormal Gibberish Emitter.
 
W

WW

Alexander said:
WW wrote:
[...]
Process exit status has really nothing to do with main() function
[that I'm talking about] return value/type.

Did you care to read the Standard?

With respect to main(), it's totally "outdated" and poorly thought out
stuff. Never wanted to reread it. ;-)

I see. That makes me wonder how do you come to criticise it. If you don't
know it.
 
T

The_Sage

Reply to article by: Andrey Tarasevich said:
Date written: Mon, 22 Sep 2003 18:43:45 -0700
MsgID:<[email protected]>
Strictly speaking, implementations are allowed to do anything they
please as long as any compliant C++ code is interpreted correctly. As an
extension, a compliant C++ compiler is allowed to accept and compile
Pascal and Fortran code and enhance you compiling experience with canned
jokes about your coding style, if its creators decided to implement this
weird functionality. Nevertheless, any code that requires such
functionality from the compiler cannot be referred to as "C++ code".

Congratulations for being the first person to talk sense in this whole entire
newsgroup.

You are correct, it isn't a recommended C++ style to use void main(), not
because it isn't compliant, but because optionally implemented code may not be
portable or readable. The issue everyone is indirectly alluding to, without even
knowing that they are, is coding style, and void main() isn't a recommended
coding style. Coding style is merely only a personal matter, not a standardized
mandate.

And that is the reason people get all bent out of shape when you talk about
using void main() -- because they have personally invested in a certain C++
style as if it were a standard or even a religious commandment, and for you to
brush aside their hallowed C++ style is like an attack on them personally. Their
personally choosen style must be the best, even if it isn't standardized and
never will be standardized, in their minds it is the Word of God and any other
style is a religion and must be supressed in the name of the C++ God.

Once again though, the issue here was never coding style or portability, it was
compliance and void main() is compliant.

An interesting sidenote: I find the ASM keyword one the most useful things of
all about C++, but guess what? Even though ASM is a part of the standard, it too
isn't a recommended part of the most C++ styles because it may not be portable
or readable. But so what? I find that many C++ programmers don't care about
portability -- and rightly so, seeing as the vast majority of all the computers
out there are Intel/Windows based anyway. As for readability, void main() is not
a problem, although ASM is a problem, since ASM is obfuscated by nature whereas
C++ is naturally clear.

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: (e-mail address removed) (Gavin Deane)
Date written: 23 Sep 2003 00:46:19 -0700
MsgID:<[email protected]>
Obviously English isn't your first language. The word is "grammar". It
is elementary English spelling.

Obviously you are wrong since you don't know the difference between a spelling
mistake and a grammatical error.

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: "Buster said:
Date written: Tue, 23 Sep 2003 03:50:56 +0100
MsgID:<[email protected]>
Tripe. The sentence has two clauses, linked by a conjunction.

Try another guess. The "but" allows for different returns types, as it is a
continuation of the first sentence, which by conicidence was about return types.

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: Noah Roberts said:
Date written: Mon, 22 Sep 2003 19:55:13 -0700
MsgID:<[email protected]>
Actually, and here is something you should think about, if you are right
then everyone else is confused including the people that wrote the
standard.

Bullshit. Like I clearly pointed out to you before, IBM, MS, and Borland agree
with me. Please explain how three major compiler manufacturere also got it
"wrong" -- at least to your interpretation of it.
If that doesn't even make you rethink your position then you
are way to arrogant for civilized converse.

Does the fact that MS, Borland, and IBM disagree with you but agree with me make
you rethink your position? Then you are way too arrogant for civilized
conversation.

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: "Attila Feher said:
Date written: Tue, 23 Sep 2003 10:19:49 +0300
MsgID:<[email protected]>
I gace you the quote. Even explained it to you. Care to read it.

And I quoted it back to where it clearly stated that additional return types
were allowed. Read it again and see what you've been missing.

In the meantime, please explain why you are unable to answer why MS, IBM, and
Borland all agree with my interpretation and not yours?

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: Andrey Tarasevich said:
Date written: Mon, 22 Sep 2003 18:52:40 -0700
MsgID:<[email protected]>
Wrong. The fact that the code is accepted by an ISO compliant compiler
doesn't mean that the code is standard.

Just because the compiler is ISO compliant doesn't mean it is ISO complaint? Oh,
I'm really convinced now! With such irrefutable "logic", who can stand up to
you?

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

Alf P. Steinbach

Obviously you are illiterate, so let me put this in terms even an illiterate
idiot like you can understand...

"3.6.1 Main function paragraph 2:
It shall have a return type of type int..."

All ISO compatible compilers like MS, Borland, and IBM conform to this.

"...but otherwise..."

See that word? It means that the standard allows breathing room for other return
types other than int. Duh!

"its type is implementation-defined"

Therefore, any compiler that implements other types of main() functions other
than int main(), such as void main(), are ISO compliant.

Perhaps you know that C++ was created by Bjarne Stroustrup. Read Bjarne's
comments on this at

<url: http://www.research.att.com/~bs/bs_faq2.html#void-main>

Quoting Bjarne from that page:

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

That is the meaning of "otherwise its type is implementation-defined"; and
since referring to authority persons is a weak argument, here's the logic:
if it were not so, the "shall have a return type of type int", which starts
the sentence you quoted from the standard, would be meaningless.

Note btw. that the above is for a _hosted_ implementation. When exactly this
debate raged in [comp.lang.c++.moderated] some time ago, wrt. Visual C++, many
of the authorities quoted in this thread as arguments against your viewpoint
insisted, quite irrationally from my perspective, that Visual C++ as used for
Windows GUI programs is simply not a hosted implementation (which if true would
render most any discussion of standard-conformance moot)... Which again goes
to show that referring to authorities is a weak argument, but I hope you catch
the logic above -- and perhaps Bjarne is sufficiently more-than-authority.

Hth.,

- Alf
 
W

WW

The_Sage said:
Congratulations for being the first person to talk sense in this
whole entire newsgroup.

You are correct, it isn't a recommended C++ style to use void main(),
not because it isn't compliant, but because optionally implemented
code may not be portable or readable.
[SNIPPED The Seriusgy Abnormal Gibberish Emittion]

A code containing void main is not compliant. It was just told to you hours
ago by the C++ spokesman of Microsoft. You need to learn to listen.
 
W

WW

The_Sage said:
Obviously you are wrong since you don't know the difference between a
spelling mistake and a grammatical error.

You are ridiculous. Since when misspelling grammar is a grammatical error?
 
W

WW

The_Sage said:
Try another guess. The "but" allows for different returns types, as
it is a continuation of the first sentence, which by conicidence was
about return types.

No, it does not. You have been told that by Herb Sutter, who *is* the
representative of Microsoft in this circles.
 
W

WW

The_Sage said:
Bullshit. Like I clearly pointed out to you before, IBM, MS, and
Borland agree with me. Please explain how three major compiler
manufacturere also got it "wrong" -- at least to your interpretation
of it.

Bullshit. MS does not aggree with you, Herb Sutter, the C++ Community
Liaison of Microsoft has just confirmed here in this thread that a code
containing a void main declaration or definition is non-conforming. A
compiler, which provides a warning that the code is non-conforming to the
standard but still chooses to compile it is conforming. But the code is
not.
Does the fact that MS, Borland, and IBM disagree with you but agree
with me make you rethink your position? Then you are way too arrogant
for civilized conversation.

Neither MS, nor Borland or IBM agree with you. If you want, I can get an
official statement from them. There is already one in this thead from
Microsoft.
 

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

Members online

Forum statistics

Threads
474,145
Messages
2,570,826
Members
47,373
Latest member
Desiree036

Latest Threads

Top