This is the mail archive of the crossgcc@cygnus.com mailing list for the crossgcc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: function reference from standard library


On Tue, 13 Oct 1998, Art Berggreen wrote:

>
> >The declaration "main ()" is equivalent to "int main ()", as it has been
> >since K&R C days.  I think that the latest ISO C standard has decreed that
> >the omission of "int" in a declaration  is an anachronism, and for this
> >reason it draws a warning from gcc.  You should change your declaration
> >to "int main (void)" [not "void main (void)" ... I don't think that's
> >considered legal anymore, if it ever was] and end the function with
> >"return 0" to stop these complaints.
>
> Functions returning void are definitely legal.  This specifies that the
> function does not return a value.  Any attempt to return with a value
> from inside the function will generate a warning.  Any attempt to use
> a return value from such a function will also generate a warning.

Yes, but main() is special and does not follow the rules for other functions.
Its signature is restricted;  in particular, the return type must be int.

See, for instance, http://www.ses.com/~clarke/cpptips/main_func, from which
the following snippet is quoted:

% RESPONSE: steve@taumet.com (Steve Clamage)
%
% It ought to make a difference, since the only valid definitions of
% main() have return type 'int' (explict or implied).  This is the case
% in both Standard C and in C++.  If you write, for example,
%         void main(){ }
% The compiler is obligated to diagnose an error in C and C++.

>
> If you don't want to use the return value of a function, it's a good
> practice to cast the return value of the function call to void.  Otherwise
> the compiler can complain that you are discarding the return value.

A warning which has seems to have fallen into disuse in recent years ...
and in my opinion, with good reason.

>
> You can also use volatile on functions (I think this is a GNU extension).
> This specifies that the function will never return.

That's something I was not aware of.

>
> Art

Mike
--
C. M. Heard/VVNET, Inc.
heard@vvnet.com

________________________________________________
To get help for the crossgcc list, send mail to
crossgcc-request@cygnus.com with the text 'help'
(without the quotes) in the body of the message.