[Home]
[Edit this page]
[Recent Changes]
[Special Pages]
[Help]
CppVoid
In C, int myFunction(void); is the declaration of a function taking no arguments. In C++, int myFunction(); is preferred (see below) to specify this. In C, however, there is a difference between the two, as in C, int myFunction(); denotes a function declaration taking ANY number of unspecified parameter.
Here a (modified) example submitted by stober:
Sorry, I haven't got a better example. I need to look in some Win32 API for one).
Avoid void* except in low-level code [2]
See void* for more details.
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
CppVoid
(C++) void
Keyword denoting that either- The function returns nothing
- The function takes no arguments (in C)
- The function takes no arguments (in C++)
- The function returns a pointer of unknown type.
The function returns nothing
void sayHello()
{
std::cout << "Hello world" << std::endl;
}
The function takes no arguments (in C)
(From the C++ MessageBoard, http://www.programmersheaven.com/c/MsgBoard/read.asp?Board=3&MsgID=339047&Setting=P0030F0001, thanks to stober)In C, int myFunction(void); is the declaration of a function taking no arguments. In C++, int myFunction(); is preferred (see below) to specify this. In C, however, there is a difference between the two, as in C, int myFunction(); denotes a function declaration taking ANY number of unspecified parameter.
Here a (modified) example submitted by stober:
void func1();
void func2(void);
int main()
{
int a = 0;
int b = 0;
func1();
func1(a);
func1(a,b);
func2(a); //Error on this line! func2 has no arguments!
}
The function takes no arguments (in C++)
This is called 'an abomination' by Bjarne Stroustrup (the creator of C++), Dennis Ritchie, the co-creator of C, and Doug McIlroy, head of the research department where Unix was born [1,3]. In [1] Bjarne Stroustrup gives the following code as example:int f(void) ; // error: abomination int g() ; // g takes no argument
The function returns a pointer of unknown data type
void* someFunction();(
Avoid void* except in low-level code [2]
See void* for more details.
'void' links
References
- 1) Bjarne Stroustrup. 2002. Sibling rivalry: C and C++. The C/C++ Users Journal of July, August and September 2002.
- 2) Bjarne Stroustrup. The C++ Programming Language (3rd edition).ISBN: 0-201-88954-4 Chapter 5.8.7: 'Avoid void* except in low-level code'.
- 3) http://www.parashift.com/c++-faq-lite/newbie.html#faq-29.4
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
