Topic: Return types for functions


Author: mhc@slip.net (Michael H. Chen)
Date: 1997/06/15
Raw View
Does anyone know where in the ANSI C++ draft I can find information on
return types for functions?

I am trying to figure out if int main() is most appropriate or if main()
is equally appropriate.

It appears that any function that returns a type int does not necessarily
have to state it explicity.  I tried compiling all functions that return
a type int without the return type, like:

                                function();

for a function that returns a type int and does not take any arguements,
and it worked.

But in most books, int is used explicitly.  While in the main() function,
most books don't use int explicitly.

If anyone can point me to the appropriate part of the C++ draft that
can clear this up for me, i'd appreciate it.



---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]





Author: David Vandevoorde <daveed@vandevoorde.com>
Date: 1997/06/16
Raw View
Michael H. Chen wrote:
> It appears that any function that returns a type int does not
> necessarily have to state it explicity.

That ``implcit int'' rule was removed from C++ a while ago.
It is also expected to be removed from C99.

> I tried compiling all
> functions that return a type int without the return type, like:
>
>                                 function();
>
> for a function that returns a type int and does not take any
> arguements, and it worked.

If your C++ compiler does not emit a warning, I would say
that it is somewhat outdated in this respect.

> But in most books, int is used explicitly.  While in the main()
> function, most books don't use int explicitly.
>
> If anyone can point me to the appropriate part of the C++ draft that
> can clear this up for me, i'd appreciate it.

It's probably implicit in the grammar ([dcl.fct] has a grammar
summary for function declarations). It's also refered to in
the compatibility (non-normative) annex ([diff.dcl]).

 Daveed
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]





Author: Marcelo Cantos <marcelo@janus.mds.rmit.edu.au>
Date: 1997/06/17
Raw View
David Vandevoorde <daveed@vandevoorde.com> writes:

> Michael H. Chen wrote:
> > It appears that any function that returns a type int does not
> > necessarily have to state it explicity.
>
> That ``implcit int'' rule was removed from C++ a while ago.
> It is also expected to be removed from C99.

Let me just point out that even if it was allowed, it should still be
strongly discouraged.  Such trite shortcuts provide no advantage
whatsoever (unless you think that saving four keystrokes for every
function that returns int is going to halve your development time --
actually the theoretical limit on time savings would be 40%, assuming
that the project consisted of nothing but single letter functions that
do nothing).


--
______________________________________________________________________
Marcelo Cantos, Research Assistant       __/_  marcelo@mds.rmit.edu.au
Multimedia Database Systems Group, RMIT   /       _ Tel 61-3-9282-2497
L2/723 Swanston St, Carlton VIC 3053, Aus/ralia ><_>Fax 61-3-9282-2490
Acknowledgements: errors - me; wisdom - God; sponsorship - RMIT
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]