TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: DANIEL HEBBERD
from: JONATHAN DE BOYNE POLLARD
date: 1997-10-29 11:23:00
subject: VOID

 DH> in a program where you use say a function called : DOHAPPY(); 
 DH> and the function requires no parameters, then it would be declared 
 DH> as:
 DH> int dohappy(void) ; 
Have you noticed which echo you are in ?  That's correct.  You are in the 
*C++* echo, not the C echo.  The above is only fully correct for the C 
language.
The C language requires the void keyword for a function with no parameters 
because a declaration containing no parameters actually represents an 
old-style "K&R" declaration where the function signature is not specified.  
The C++ language, on the other hand, does not allow K&R style declarations at 
all, because function overloading *requires* all function declarations to 
have a signature.  So in C++ a function that has no parameters is declared, 
sensibly enough, with no parameters:
        int dohappy() ;
The "(void)" syntax is allowed in C++, but it is only for C compatibility.  
And it is only in C in the first place because the C syntax could not be made 
fully orthogonal lest it break legacy K&R code.
Note, incidentally, that K&R style declarations are deprecated in Standard C. 
 They may well go away in the next revision of the language (which is being 
worked on now).  If they do, it is most likely that a declaration with no 
parameters in C will then mean exactly what it means in C++.  In which case, 
the "(void)" syntax will probably be deprecated in both C and C++.
 ¯ JdeBP ®
--- FleetStreet 1.19 NR
---------------
* Origin: JdeBP's point, using Squish (2:440/4.3)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.