Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Happy New Year!

Reply
Thread Tools

Happy New Year!

 
 
Ioannis Vranos
Guest
Posts: n/a
 
      12-31-2004
#include <iostream>


int main()
{
using namespace std;

cout<<"Best wishes for a Great Happy New Year to all!"<<endl;
}



--
Ioannis Vranos

http://www23.brinkster.com/noicys
 
Reply With Quote
 
 
 
 
Jon Wilson
Guest
Posts: n/a
 
      12-31-2004
Ioannis Vranos wrote:
> #include <iostream>
>
>
> int main()
> {
> using namespace std;
>
> cout<<"Best wishes for a Great Happy New Year to all!"<<endl;
> }
>
>
>



This should give a compiler warning. You declare int main(), but have
no return statement.
 
Reply With Quote
 
 
 
 
Jonathan Mcdougall
Guest
Posts: n/a
 
      12-31-2004
Jon Wilson wrote:
> Ioannis Vranos wrote:
>
>>#include <iostream>
>>
>>
>>int main()
>>{
>> using namespace std;
>>
>> cout<<"Best wishes for a Great Happy New Year to all!"<<endl;
>>}
>>

> This should give a compiler warning. You declare int main(), but have
> no return statement.


Not on a conforming compiler.


Jonathan
 
Reply With Quote
 
Mike Wahler
Guest
Posts: n/a
 
      12-31-2004

"Jon Wilson" <(E-Mail Removed)> wrote in message
news:YJeBd.667039$D%.153030@attbi_s51...
> Ioannis Vranos wrote:
> > #include <iostream>
> >
> >
> > int main()
> > {
> > using namespace std;
> >
> > cout<<"Best wishes for a Great Happy New Year to all!"<<endl;
> > }
> >
> >
> >

>
>
> This should give a compiler warning. You declare int main(), but have
> no return statement.


No return statement is required. When it is not specified,
the program performs an implicit 'return 0'. This is the case
only for the 'main()' function.

-Mike


 
Reply With Quote
 
Florian Quetting
Guest
Posts: n/a
 
      12-31-2004
gcc without options wouldn't give a warning, but what about -Wall?

Jonathan Mcdougall wrote:

> Jon Wilson wrote:
>> Ioannis Vranos wrote:
>>
>>>#include <iostream>
>>>
>>>
>>>int main()
>>>{
>>> using namespace std;
>>>
>>> cout<<"Best wishes for a Great Happy New Year to all!"<<endl;
>>>}
>>>

>> This should give a compiler warning. You declare int main(), but have
>> no return statement.

>
> Not on a conforming compiler.
>
>
> Jonathan


 
Reply With Quote
 
KPB
Guest
Posts: n/a
 
      12-31-2004
Florian Quetting wrote:
> gcc without options wouldn't give a warning, but what about -Wall?


No. As others have said, the return statement is not needed.

This was one of those weird facts that I didn't know about until
recently. I just include the return statement without thinking about it.
I think I read this fact in one of the Josuttis books.

Also, I did try out the -Wall just to make sure.

To me, this is similar to the variable initialization issue. Some are
init'd implicitly (if you don't initialize them explicitly) and some
aren't. I just explicitly initialize everything then I don't have to
remember which are and which aren't.

KPB
 
Reply With Quote
 
Victor Bazarov
Guest
Posts: n/a
 
      12-31-2004
"Jon Wilson" <(E-Mail Removed)> wrote...
> Ioannis Vranos wrote:
>> #include <iostream>
>>
>>
>> int main()
>> {
>> using namespace std;
>>
>> cout<<"Best wishes for a Great Happy New Year to all!"<<endl;
>> }
>>
>>
>>

>
>
> This should give a compiler warning. You declare int main(), but have no
> return statement.


Actually that's not a problem (see other replies). However, a strictly
conforming implementation has to complain about 'endl' being undefined.
To find it, include <ostream> as well.

Happy New Year!

Victor


 
Reply With Quote
 
David Harmon
Guest
Posts: n/a
 
      12-31-2004
On Fri, 31 Dec 2004 16:02:00 GMT in comp.lang.c++, Jon Wilson
<(E-Mail Removed)> wrote,
>Ioannis Vranos wrote:
>> #include <iostream>
>>
>>
>> int main()
>> {
>> using namespace std;
>>
>> cout<<"Best wishes for a Great Happy New Year to all!"<<endl;
>> }
>>

>
>This should give a compiler warning. You declare int main(), but have
>no return statement.


The compiler may give any warning it wants, but it shouldn't for
that. main() has a special exemption and is allowed to have no
return statement.

The output line should be
cout<<"Best wishes for a Great Happy New Year to all!\n";

It is useless and wasteful to use endl to flush the stream,
immediately before the program is going to end and flush it anyway.


 
Reply With Quote
 
Mike Wahler
Guest
Posts: n/a
 
      12-31-2004

"KPB" <(E-Mail Removed)> wrote in message news:3xgBd.340$(E-Mail Removed)...
> Florian Quetting wrote:
> > gcc without options wouldn't give a warning, but what about -Wall?

>
> No. As others have said, the return statement is not needed.


Correct (this only applies to 'main()'

>
> This was one of those weird facts that I didn't know about until
> recently. I just include the return statement without thinking about it.


Actually, I and others feel that this constitutes 'good
practice' anyway. But it is incorrect to state that
omitting it is invalid.

> I think I read this fact in one of the Josuttis books.


It's also cited in many others.

>
> Also, I did try out the -Wall just to make sure.


That's the wrong way to determine how the language should
work.

>
> To me, this is similar to the variable initialization issue. Some are
> init'd implicitly (if you don't initialize them explicitly) and some
> aren't. I just explicitly initialize everything then I don't have to
> remember which are and which aren't.


Aa matter of 'habit', I will usually initialize every
object I define, regardless of its storage duration.
But the issue of which objects are automatically
initialized and which are not is straightforward:

1) Static storage duration objects are automatically default initialized.
2) Objects with any other storage duration are not automatically
initialized.
3) ("Special case") If one or more of an array's elements are explicitly
initialized, any elements for which there are no corresponding
initializers
are default inititalized.


-Mike


 
Reply With Quote
 
adbarnet
Guest
Posts: n/a
 
      12-31-2004
...and - without some kind of <stdheader> include the compiler doesn't know
anything about the namespace 'std' in any case - so the using statement
should blow!

Indeed - Happy New Year!


"Victor Bazarov" <(E-Mail Removed)> wrote in message
news:2JgBd.667542$D%.148039@attbi_s51...
> "Jon Wilson" <(E-Mail Removed)> wrote...
>> Ioannis Vranos wrote:
>>> #include <iostream>
>>>
>>>
>>> int main()
>>> {
>>> using namespace std;
>>>
>>> cout<<"Best wishes for a Great Happy New Year to all!"<<endl;
>>> }
>>>
>>>
>>>

>>
>>
>> This should give a compiler warning. You declare int main(), but have no
>> return statement.

>
> Actually that's not a problem (see other replies). However, a strictly
> conforming implementation has to complain about 'endl' being undefined.
> To find it, include <ostream> as well.
>
> Happy New Year!
>
> Victor
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
OT: Happy Happy Joy Joy! Mike T. MCSE 79 11-19-2006 08:22 PM
[QUIZ SOLUTION] Happy Numbers (#93) - happy bases Daniel Martin Ruby 1 09-06-2006 07:06 PM
HEXUS.opinions :: Have a happy happy gaming holiday Silverstrand Front Page News 0 12-23-2005 04:12 PM
Happy Happy Joy Joy, I recovered my photos Tama Mativa Digital Photography 9 05-24-2004 04:58 PM
happy happy christmas showgun MCSE 26 12-17-2003 07:11 PM



Advertisments