Mail Archives: djgpp/1998/08/14/06:07:30
On Fri, 14 Aug 1998 04:28:23 GMT, Merlin <merlin__ AT geocities DOT com>
wrote:
>Gerhard Gruber wrote:
>
>> Destination: Merlin <merlin__ AT geocities DOT com>
>> From: Gruber Gerhard
>> Group: comp.os.msdos.djgpp
>> Date: Thu, 13 Aug 1998 08:16:15 GMT:
>>
>> >> No, this isn't a prototype. This is:
>> >>
>> >> void do_nothing(void);
>> >
>> > if you leave the void in brackets out it will be assumed..
>>
>> That's wrong.
>>
>> The function(void) means that you specifically say that these function takes
>> no arguments. a call like this function(i) yields an error. If you leave the
>> void out then this means you don't give the compiler a hint what this function
>> takes. writing function() or function(i) or function(a, b, c, d, e) is
>> considered valid in this case, so leaving the void out is not the default vor
>> void. It is totaly different.
>
>wow...i didn't know this...i was told it was assumed...
You are referring to C++ then. C++ is not C.
In C++
void f(void);
and
void f();
are both _prototypes_, and () is _identical_ to (void) in this case,
i.e. void is _assumed_.
In C
void f(void);
is a prototype and
void f();
is a function declaration without a prototype. It means that the
number of parameters f should get is known to the programmer.
>but i still suppose that leaving void out would be ok... I mean it would be silly
>to pass parameters to a function that didn't require any. So in effect it would
>turn out pretty much the same whether or not you specify void in the brackets or
>not...
Of course it's ok - if you are a superman and never make unintentional
mistakes. The purpose of prototypes is to allow the compiler to do
error checking. Why would you intentionally refuse to accept this help
if it is for free ?
Humans may fail, and programmers are humans. Usually...
Regards
Horst
- Raw text -