Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Function objects

Reply
Thread Tools

Function objects

 
 
anderberg
Guest
Posts: n/a
 
      12-16-2005
On 2005-12-07, Default User wrote:
> Alf P. Steinbach wrote:
>
>> * anderberg:

>
>> > {
>> > Functor();
>> > return 0;

>>
>> Not necessary in 'main', because 'main' is a special function.

>
> While techinically true, it's not any kind of error to include the
> return. I always include it. If nothing else, it signals to the
> maintainer that the original programmer didn't just forget about the
> return, that 0 was indeed what was meant.
>
> Some compilers will flag it with a warning.
>
> Many common coding standards mandate the use of explict returns in
> main().


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

"Note also that neither ISO C++ nor C99 allows you to leave
the type out of a declaration. That is, in contrast to C89
and ARM C++ ,"int" is not assumed where a type is missing in a
declaration. Consequently:

#include<iostream>

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

is an error because the return type of main() is missing."

--
anderberg: People are just mutations. Some worse than others.
 
Reply With Quote
 
 
 
 
Rolf Magnus
Guest
Posts: n/a
 
      12-16-2005
anderberg wrote:

>>> * anderberg:

>>
>>> > {
>>> > Functor();
>>> > return 0;
>>>
>>> Not necessary in 'main', because 'main' is a special function.

>>
>> While techinically true, it's not any kind of error to include the
>> return. I always include it. If nothing else, it signals to the
>> maintainer that the original programmer didn't just forget about the
>> return, that 0 was indeed what was meant.
>>
>> Some compilers will flag it with a warning.
>>
>> Many common coding standards mandate the use of explict returns in
>> main().

>
> http://www.research.att.com/~bs/bs_faq2.html#void-main says
>
> "Note also that neither ISO C++ nor C99 allows you to leave
> the type out of a declaration. That is, in contrast to C89
> and ARM C++ ,"int" is not assumed where a type is missing in a
> declaration. Consequently:
>
> #include<iostream>
>
> main() { /* ... */ }
>
> is an error because the return type of main() is missing."


Yes, however, that's only talking about the return _type_, not about the
explicit return statement.
I.e.:

int main() { }

is not an error, even though a return is missing.

 
Reply With Quote
 
 
 
 
Default User
Guest
Posts: n/a
 
      12-16-2005
anderberg wrote:

> On 2005-12-07, Default User wrote:
> > Alf P. Steinbach wrote:
> >
> >> * anderberg:

> >
> >> > {
> >> > Functor();
> >> > return 0;
> >>
> >> Not necessary in 'main', because 'main' is a special function.

> >
> > While techinically true, it's not any kind of error to include the
> > return. I always include it. If nothing else, it signals to the
> > maintainer that the original programmer didn't just forget about the
> > return, that 0 was indeed what was meant.
> >
> > Some compilers will flag it with a warning.
> >
> > Many common coding standards mandate the use of explict returns in
> > main().

>
> http://www.research.att.com/~bs/bs_faq2.html#void-main says
>
> "Note also that neither ISO C++ nor C99 allows you to leave
> the type out of a declaration. That is, in contrast to C89
> and ARM C++ ,"int" is not assumed where a type is missing in a
> declaration. Consequently:
>
> #include<iostream>
>
> main() { /* ... */ }
>
> is an error because the return type of main() is missing."



You are confused about what we were discussing. We were going over this
programming idiom:

int main()
{
// do stuff
}

Versus:

int main()
{
// do stuff

return 0;
}


Alf points out, correctly, that the return statement is not required in
main() because the standard mandates that falling off the end for that
function (alone) is the equivalent to returning 0. I prefer to have
explicit returns anyway.


Brian


 
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
class objects, method objects, function objects 7stud Python 11 03-20-2007 06:05 PM
Function objects vs. function pointers Protoman C++ 11 12-09-2005 10:49 AM
Unable to serialize the session state. Please note that non-serializable objects or MarshalByRef objects are not permitted when session state mode is 'StateServer' or 'SQLServer'. Mike Larkin ASP .Net 1 05-23-2005 12:33 PM
write a function such that when ever i call this function in some other function .it should give me tha data type and value of calling function parameter komal C++ 6 01-25-2005 11:13 AM
Re: function objects instead of function pointers? Brian C++ 2 10-31-2003 01:45 PM



Advertisments