[Courses] Absolute Beginning C: void?

Kelly Martin kelly.lynn.martin at gmail.com
Mon Feb 6 06:18:57 UTC 2012


On Mon, Feb 6, 2012 at 12:12 AM, jim <jim at well.com> wrote:

>
>
>    As to void for arguments, prototyping is basically
> declaring a function, in my (limited) experience as a
> matter of smoothing the way for functions other than
> main that are in a particular file.
>
> void myfunc();
>    /* declares myfunc to be a function that takes no
>       arguments and does not return anything.
>    */ // comment delimiter style pointers, anyone?
>
> // I'm surmising that
> void myfunk(void);
>    /* declares myfunk identically as the declaration
>       (prototype) of myfunc above. */
>
> // It's silly code, but what about
> void myfunny(void, void, void)
>    /* takes three nothings-at-all passed in. If I
>       were the compiler I'd at least kick out a
>       warning about smart-asses.
>    */
>
>
The first declares myfunc as a function that returns nothing and takes
unspecified arguments.  Such a declaration is deprecated under C99.

The second declares myfunc as a function that returns nothing and takes no
arguments.

The third is a syntax error: "test.c:1: error: 'void' must be the only
parameter" is gcc's complaint to that prototype.

Note that the first and the second are *not* equivalent.  The first gives
the compiler no information about the arguments, while the second
explicitly says that the function takes no arguments.  The reason behind
this is (of course) historical.

Kelly


More information about the Courses mailing list