Seungbeom Kim wrote:
> Alberto Ganesh Barbati wrote:
>> Kush ha scritto:
>>>
>>> RunProgram::RunProgram(void)
>>> {}
>>
>> The use of "(void)" is provided for backward compatibility with C and
is
>> frowned upon in a C++ program. Just write "()".
>
> I have wondered, why is it frowned upon in a C++ program? I don't see
> any harm there. Did I miss anything? Is it deprecated or anything?
>
> Actually it may even be better in a header file shared by C and C++,
> because it means exactly the same thing both in C and C++: both f() and
> f(void) in C++ means f(void) in C, but f() in C means something else.
> In addition, in a sense, it's more consistent across the parameter list
> and the return type ("use void to mean nothing").
>
> I know we really don't have to type the four additional characters,
> but I don't see the point in bothering to point out that it shouldn't
> be used. If there's any, can you please explain it?
The most useful answer would be that the inventor of the language
intended the empty argument list to mean an empty argument list, not an
unspecified argument list (as it is in C). Thus the argument list
`(void)` is unnecessary and included only for C compatibility.
Scanning through _The C++ Programming Language_ 3e, you'd be hard
pressed to find Stroustrup even mentioning the backward-compatibility
syntax. A quick scan through _Design and Evolution of C++__ also
doesn't seem to think it significant enough to warrant mention. It's of
course indicated in the C++ Standard (8.3.5/2), but only in one sentence
without fanfare. And the vast majority of the examples in all three
books use the empty argument list syntax, not `(void)`.
--
Erik Max Francis && max@[EMAIL PROTECTED]
&& http://www.alcyone.com/max/
San Jose, CA, USA && 37 18 N 121 57 W && AIM, Y!M erikmaxfrancis
Grub first, then ethics.
-- Bertolt Brecht
[ See http://www.gotw.ca/resources/clcm.htm
for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


|