[Courses] Absolute Beginning C: void?
jim
jim at well.com
Mon Feb 6 06:12:25 UTC 2012
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.
*/
On Sun, 2012-02-05 at 23:04 -0600, Kelly Martin wrote:
> On Sun, Feb 5, 2012 at 10:48 PM, techno curmudgeon <
> technocurmudgeon at gmail.com> wrote:
>
> > In looking around (extracurricular reading? I never even did that in
> > university!) a lot of the 'hello world' examples start with 'void' in
> > front of main().
> >
> > Researching "void" almost always says words to the effect "is the type
> > for a function does not return a value"...OK, got that.
> >
> > Then they launch into wildly gobbledegooky jargon about other uses.
> > Including "A C prototype taking no arguments, e.g. void f() above, has
> > been deprecated however in C99" (from a footnote in
> > http://en.wikipedia.org/wiki/Void_type).
> >
> > I don't want to get too off track here. Since hello world worked, a
> > void keyword is not required (right?). And since it didn't generate a
> > warning, it's not even bad form not to have one, right?
> >
> > I guess that's my question. While not needed, is it good practice to
> > use the 'void' keyword?
> >
> > Thanks!
> > _______________________________________________
> > Courses mailing list
> > Courses at linuxchix.org
> > http://mailman.linuxchix.org/mailman/listinfo/courses
> >
>
> I'm sure someone will correct me if I'm wrong, but what I recall being
> deprecated is not the use of void as the return type, but the use of an
> empty argument list (that is, the "()" in "void f()") in function
> prototypes.
>
> Technically, what an empty argument list means is "arguments are
> unspecified", and the resulting function prototype yields a function which
> may permissibly be called with any number of arguments. The C99 standard
> specifies that a function that takes no arguments shall be prototyped as
> "<returntype> f(void)", where the "(void)" indicates that the function
> explicitly takes no arguments. Calling a function with an explicitly void
> formal argument list with any number of actual arguments other than zero is
> an compile-time error. Calling a function prototyped with an unspecified
> formal argument list (or with no prototype at all) with any number of
> arguments other than zero generates, at most, a warning.
>
> This has nothing to do with specifying a return type of void, which one
> should always declare for functions that do not have a return value.
>
> Kelly
> _______________________________________________
> Courses mailing list
> Courses at linuxchix.org
> http://mailman.linuxchix.org/mailman/listinfo/courses
More information about the Courses
mailing list