Re: Endless loop question

From: Flash Gordon (spam_at_flash-gordon.me.uk)
Date: 09/29/04


Date: Wed, 29 Sep 2004 20:19:13 +0100

On Wed, 29 Sep 2004 18:30:11 +0000 (UTC)
dj3vande@csclub.uwaterloo.ca (Dave Vandervies) wrote:

> In article <07vll0dmhqi8mgikmh7gtdk1qs1crqqk0s@4ax.com>,
> Alan Balmer <albalmer@spamcop.net> wrote:
> >On 29 Sep 2004 18:11:07 GMT, "S.Tobias" <sNOiSPAMt@amu.edu.pl> wrote:
> >
> >>Mark A. Odell <odellmark@hotmail.com> wrote:
> >>> phaza7@yahoo.com (Tweaxor) wrote in
> >>> news:1c0c25ba.0409290912.14fefb61@posting.google.com:
> >>
> >>> > int main() {
> >>> Ick ^^^^^^^^
> >>
> >>> int main(void)
> >>> {
> >>
> >>No, why? You can drop `void' in function definition, can't you?
> >
> >They mean different things. '(void)' tells the compiler there are no
> >arguments. '()' tells the compiler that the arguments are
> >unspecified.
>
> In this case, though, the distinction doesn't make any difference; one
> form means "Here's the definition of a function called main, returning
> int and taking no arguments, without a prototype" and the other form
> means "Here's the definition of a function called main, returning int
> and taking no arguments, with a prototype".

So why not give the compiler all the information you have? It's
generally a good habit and if you[1] break it for main you are likely to
break it for other functions.

> Unless, of course, you're planning on calling main later on with a
> nonempty argument list. But if you really want to lie to the
> compiler, a prototype won't stop you either.

Actually, if there is a prototype in scope and you pass an incorrect
number of parameters the compiler is (I believe) *required* to produce a
diagnostic.

[1] The generic you, not the specific you.

-- 
Flash Gordon
Sometimes I think shooting would be far too good for some people.
Although my email address says spam, it is real and I read it.


Relevant Pages

  • Re: C Questions
    ... No prototype is given for this function, so the compiler cannot ... To prototype a function with no parameters, use void: ... %d takes an int argument, ...
    (comp.lang.c)
  • Re: program having printf() function invocation without including
    ... warning and would assume that it would return a int, ... The prototype is primarily for the compiler's benifit, ... It helps the compiler to output the ... the label 'printf'/'_printf' and link in the object code. ...
    (comp.lang.c)
  • Re: To coerce or not...? struct sockaddr vs struct sockaddr_in
    ... that "pointer to struct X" and "pointer to struct Y" are not ... prototype, if it has one -- and apparently it does on your system ... this instructs the compiler to truncate the ".14" part, ... Grabbing an "int", when the compiler passed ...
    (comp.lang.c)
  • Re: derangement: coding review request
    ... > The declaration or prototype tells the compiler what type of arguments to ... > an int then feeding it a pointer will cause it to fetch an int from the ... > club tie and pouring brake fluid on his porsche. ...
    (comp.lang.c)
  • Re: The importance of prototypes
    ... >> eliminating compiler warning messages). ... I added the prototype and the problem went away. ... >> integer arguments and thus puts in a type cast for me? ... > argument, and you pass it an int, you must cast the int to double. ...
    (comp.lang.c)