And Google will tell you.
c++ - What is the difference between function() and function(void)?
Featuring references to both the
C
andC++
standards.Understanding the difference between f() and f(void) in C and C++ once and for all
Featuring references to
C99
andC11
standards.Is there a difference between foo(void) and foo() in C++ or C
Featuring simple explanation and the reference to
K&R C
Besides example scenarios in the aforementioned readings, there still exist some circumstances where the difference has to be taken into consideration carefully and seriously.
Case 1. Win32 API: CallWindowProc
You know as usual, RTFM, CallWindowProc.
Especially the section Remarks
, around the sentence
This subtle distinction can break careless code.
,
deserves a serious reading.
In the very beginning
when encoutered with btVoid
and btNoType
,
we didn't think of this difference,
notwithstanding the fact that we have understood
this difference several years ago before starting PdbReader.
And before recognizing that btVoid
corresponds to (void)
while btNoType
to ()
,
we used __NoType__
as a temporary placeholder for btNoType
,
which is, however, strange and incorrect.
As in Issue #1, it's the PFNCLIENT
structure from win32k.sys
that causes troubles.
Later, when our further investigation
on PFNCLIENT
and WndProc
led us to CallWindowProc,
it suddenly occurred to us
that btNoType
should correspond to ()
.
It's this very subtle and seemingly trivial distinction that leads us to writing some wrong code and producing wrong results. In fact, that's why we wrote this article and curated a list of relevant materials, which are intended to serve as takeaways for us and precautions to others.
Simply put, keep the distinction in mind
and don't use ()
in C
, unless you are 100% confident
that you want the arguments unspecified,
which might be useful in some cases.
As a matter of fact, it very likely that there are still many more situations where the difference can causing problems.