Click here to Skip to main content
15,912,493 members
Please Sign up or sign in to vote.
3.29/5 (4 votes)
See more: (untagged)
void getdata(void)

it also work with blank bracket then why?
Posted
Updated 28-May-12 11:15am
v2
Comments
Sergey Alexandrovich Kryukov 28-May-12 14:09pm    
Do you think there is only one language in the world, the one you are familiar with? :-) Tag it.
--SA

The simple answer is: "why not"? The empty list in round brackets is very natural, it means "no arguments" are passed to the function in question, "empty argument list". It's rather using void parameter is quite a perverted, historical syntax, which is going out of practice. Just think about, why its function(void); why not function(void, void)? :-) Why an empty list, that is, a list with zero elements, should be expressed as a list of one element? Very artificial syntax agreement, no wonder it's now used anywhere else and hardly used in modern C/C++ code.

—SA
 
Share this answer
 
v3
Comments
OriginalGriff 28-May-12 14:22pm    
That's not quite true for C
void foo();
is not the same as
void foo(void);
The former is a "acceptable" prototype for a function taking any parameters rather than a function taking no parameters (depreciated in C 1999)
Sergey Alexandrovich Kryukov 28-May-12 14:31pm    
Thank you very much for this note. By the way, 1) OP did not specify the language, so this is all of somewhat abstract character, 2) this fact is yet another reason to avoid using foo(void).
--SA
OriginalGriff 28-May-12 14:35pm    
Very true in both cases! :laugh:
Sergey Alexandrovich Kryukov 28-May-12 15:25pm    
:-)
--SA
Andreas Gieriet 28-May-12 16:23pm    
My 5 too.
Andi
If you are using C++, then there is no difference, it is a "hangover" from the base language C
C++
void foo(void) {}

is the equivelent of
C++
void foo();
In that they both declare a function that takes no parameters.

However, in C the situation is a little different:
C++
void foo(void);
Declares a function that takes no parameters.
C++
void foo();
Declares a function that will take any parameters. (This usage was depreciated in the 1999 C spec).
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 28-May-12 14:31pm    
Sure, a 5.
--SA
Andreas Gieriet 28-May-12 16:23pm    
My 5 too.
Andi
You talk about C or C++, right?
The designers of the language decided to allow both variations of function declarations:
C++
SomeType F() { ... }

and
C++
SomeType F(void) { ... }

are equivalent.

Cheers
Andi
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 28-May-12 14:15pm    
Of course, a 5. We were writing our answers at the same time, you might be curious enough to see mine...
--SA
Andreas Gieriet 28-May-12 16:20pm    
Yeah. We happen to respond at similar times again ;-)
Cheers
Andi

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900