In C, func() and func(void) have different function signature.
(But, in C++, these two are same.)
'func()' means 'this function can have any number of arguments (0 ~ infinite)'.
But, 'func(void)' means 'this function doesn't have argument.'
See following example.
#ifdef CASE1 void func(void); /* (1) */ #else void func(); /* (2) */ #endif void func(int i) { ; /* do something */ }
If 'CASE1' is defined, compiling this file complains error like "error: conflicting types for 'func'".
But, 'CASE1' is not defined, this is well-compiled.
Now, you can clearly understand difference.
So, using 'func(void)' is better for readibility if 'func' really doesn't have any arguement, instead of just 'func()'.
*** One more. ***
In C, 'extern' for function is default visibility.
So, in function declaration, 'extern void func(void);' is exactly same with 'void func(void);'.
Therefore any of them is OK.
( [ omitting 'extern' for simplicity ] vs. [ using 'extern' to increase readability ] )
But, default visibility of function depends on compiler.
For portability reason, using macro is usually better instead of using explicit directive - especially at shared library header.
(Ex. 'EXTERN void func(void)')
'Language > C&C++' 카테고리의 다른 글
[C/C++] enable/disable function/macro with define switch. (0) | 2011.11.23 |
---|---|
[C/C++] Fail to build Android with g++/gcc-4.6 (Ubuntu-11.10) (0) | 2011.10.17 |
[C/C++] Tips for OOP - module initialization. (0) | 2011.05.17 |
[Linux][C/C++] strange pipe issue in linux in 'ylisp'. (0) | 2011.02.09 |
[C/C++][Linux] Avoiding making zombie process (0) | 2010.12.14 |