On 2012-07-17 17:11, Regan Heath wrote:

Ahh, I've been looking at the ANSI C spec and assuming that is what
you're basing things off, K&R C was pre-ANSI C and may have different
rules.  I think you should probably aim to be ANSI C compliant and
above, and ignore K&R.

This page says otherwise:

http://en.wikipedia.org/wiki/ANSI_C#Compliance_detectability

"...while an obsolescent non-prototype declaration is used otherwise. Those are still ANSI-compliant as of C99 and C90, but their use is discouraged".

Looking at the ANSI C spec again, section 6.7.5.3, item 10 says:

"The special case of an unnamed parameter of type void as the only item
in the list specifies that the function has no parameters."

So, "void" indicates no parameters..

Item 14 is also applicable and says:

"An identifier list declares only the identifiers of the parameters of
the function. An empty list in a function declarator that is part of a
definition of that function specifies that the function has no
parameters. The empty list in a function declarator that is not part of
a definition of that function specifies that no information about the
number or types of the parameters is supplied." 124)

The latter part of that is applicable to declarations in header files
(the former is for definitions in c files);  "The empty list in a
function declarator that is /not part of a definition of that function/
specifies that /no information about the number or types of the
parameters is supplied/."

So, a function like:
     int foo();

in a header "specifies that no information about the number or types of
the parameters is supplied".

However footnote 124) says see 6.1.6, and 6.1.6 says:

6.11.6 Function declarators
The use of function declarators with empty parentheses (not
prototype-format parameter type declarators) is an obsolescent feature.

So, coming full circle, it seems like I'm right after all .. I think.
"void" is required to indicate no parameters and () is obsolete in ANSI C.

It's still in the standard.

--
/Jacob Carlborg


Reply via email to