[comp.lang.c] ANSI C function declaration prototypes

rja@edison.GE.COM (rja) (01/18/89)

I am trying to revise some code to make it more maintainable.
As part of this, I am trying to correctly have the code use
ANSI C function prototypes.  I've got a couple of questions
that I can't seem to find the answer to in references at hand.

1) How should I declare a function using prototypes when
   that function has no parameters ??
example:   int foo();

My compiler sees no parameters and generates a warning about
the lack of ANSI function prototypes.


2) How should I declare a function which truly returns nothing ?

   My first thought was to declare "void foo();" but that still
   causes my compiler to warn about a function with no return value
   when it compiles the function definition.


Perhaps these are cases where the programmer should just ignore the
compiler warnings, but I'd really like to have a minimum number
( preferably zero) of warnings.

 Ran
______________________________________________________________________________
         rja@edison.GE.COM      or      ...uunet!virginia!edison!rja  
     via Internet (preferable)          via uucp  (if you must)
______________________________________________________________________________

gwyn@smoke.BRL.MIL (Doug Gwyn ) (01/21/89)

In article <1776@edison.GE.COM> rja@edison.GE.COM (rja) writes:
>1) How should I declare a function using prototypes when
>   that function has no parameters ??
>example:   int foo();

That means, in ANSI C, the same as in pre-ANSI C, namely, nothing
is specified about the (fixed) number or types of the arguments.

What you want in ANSI C is
	int foo(void);
Actually, the form you gave is 100% compatible with this, but it
does not allow the compiler to check for correct (empty) usage of
the arguments to the function.

>2) How should I declare a function which truly returns nothing ?

	void foo(/*whatever*/);

>   My first thought was to declare "void foo();" but that still
>   causes my compiler to warn about a function with no return value
>   when it compiles the function definition.

My guess is that the function definition neglects to specify "void"
return type.