Well, if this post is not that off-posting ...
> 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?
>
Here I agree with Alberto that using void for empty parameter list in
C++ is not a good programming style.
For the following C++ code
void foo(void){}
I always wondering how much the writer knows the C++ language.
(and, yes, it does cost 4 extra typing )
Of course, it is an issue of style, YMMV. :-)
> 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").
IMHO, header file is not an issue there.
Mixing C and C++ requires quite a lot extra work and add the void
only won't help at all for the real-world code. And, even if we must
to mix C and C++, since the void is a must for C and it is better
style to use empty parentheses to distinguish C++ code from C
code, IMHO.
BTW, in C99, function declarator with empty parentheses is now
an obsolescent feature (6.11.6). It is a good news since less
confusion will be made in the future for this issue.
> 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 only point I can think of is, well, protecting our fingers and
keyboard :-) , but as you mentioned above, why don't we do the
same job using the simple way?
Jiang
--
[ See http://www.gotw.ca/resources/clcm.htm
for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


|