July 17, 2012
On 2012-07-17 16:36, Regan Heath wrote:

> I believe old-style no parameter function declarations MUST have "void"
> i.e.
>
>      int foo(void);

That is still the case, regardless of "style"?

> They cannot read:
>
>      int foo();
>
> The latter MUST have parameters, we just can't tell what they are.

Take a look at this:

http://en.wikipedia.org/wiki/K%26R_C#KRC

In that example none of the functions have any parameters declared and are not called with any arguments.

-- 
/Jacob Carlborg


July 17, 2012
On 2012-07-17 16:37, Regan Heath wrote:

> All my googling for "old style" "variadic" etc returned the use of
> va_alist and va_dcl so I can't see where/why Clang would do what it's
> doing.

To be accurate it's the libclang function "clang_isFunctionTypeVariadic" that returns true.

http://clang.llvm.org/doxygen/group__CINDEX__TYPES.html#ga343b2463b0ed4b259739242cf26c3ae2 


-- 
/Jacob Carlborg


July 17, 2012
On 17/07/2012 08:56, Jacob Carlborg wrote:
> To my understanding this is legal C :
>
> int foo ();
>
> It's a K&R-style variadic functions, while their use is discouraged,
> they're still legal C.
>
> If I, in D, declare a variadic function with C linkage that doesn't
> take, at least, one regular parameter the compiler will complain.
>
> extern (C) int foo (...);
>

It is used in testfptr.d from dmd's testsuite.
July 17, 2012
On Tue, 17 Jul 2012 15:46:34 +0100, Jacob Carlborg <doob@me.com> wrote:

> On 2012-07-17 16:36, Regan Heath wrote:
>
>> I believe old-style no parameter function declarations MUST have "void"
>> i.e.
>>
>>      int foo(void);
>
> That is still the case, regardless of "style"?
>
>> They cannot read:
>>
>>      int foo();
>>
>> The latter MUST have parameters, we just can't tell what they are.
>
> Take a look at this:
>
> http://en.wikipedia.org/wiki/K%26R_C#KRC
>
> In that example none of the functions have any parameters declared and are not called with any arguments.

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.

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.

R

-- 
Using Opera's revolutionary email client: http://www.opera.com/mail/
July 17, 2012
On Tue, 17 Jul 2012 15:50:27 +0100, Jacob Carlborg <doob@me.com> wrote:

> On 2012-07-17 16:37, Regan Heath wrote:
>
>> All my googling for "old style" "variadic" etc returned the use of
>> va_alist and va_dcl so I can't see where/why Clang would do what it's
>> doing.
>
> To be accurate it's the libclang function "clang_isFunctionTypeVariadic" that returns true.
>
> http://clang.llvm.org/doxygen/group__CINDEX__TYPES.html#ga343b2463b0ed4b259739242cf26c3ae2

Is Clang open source, can we see the code for that function?  Perhaps it's a bug.. ANSI C may have made () without "void" obsolete, but no compiler I've ever used has actually enforced that - or perhaps C++ made old-style function definition/declarations obsolete and allowed () back again.

R

-- 
Using Opera's revolutionary email client: http://www.opera.com/mail/
July 17, 2012
On Tue, 17 Jul 2012 15:46:34 +0100, Jacob Carlborg <doob@me.com> wrote:

> On 2012-07-17 16:36, Regan Heath wrote:
>
>> I believe old-style no parameter function declarations MUST have "void"
>> i.e.
>>
>>      int foo(void);
>
> That is still the case, regardless of "style"?
>
>> They cannot read:
>>
>>      int foo();
>>
>> The latter MUST have parameters, we just can't tell what they are.
>
> Take a look at this:
>
> http://en.wikipedia.org/wiki/K%26R_C#KRC
>
> In that example none of the functions have any parameters declared and are not called with any arguments.

K&R C did not allow you to declare arguments at all, according to the wiki:

"Since K&R function declarations did not include any information about function arguments, function parameter type checks were not performed, although some compilers would issue a warning message if a local function was called with the wrong number of arguments, or if multiple calls to an external function used different numbers or types of arguments. Separate tools such as Unix's lint utility were developed that (among other things) could check for consistency of function use across multiple source files."

So all K&R function declarations were <name>() with no parameters.

R

-- 
Using Opera's revolutionary email client: http://www.opera.com/mail/
July 17, 2012
"deadalnix" <deadalnix@gmail.com> wrote in message news:ju3uqc$55g$1@digitalmars.com...
>
> It is used in testfptr.d from dmd's testsuite.

No, that's a D-linkage variadic.


July 17, 2012
On Tuesday, 17 July 2012 at 15:16:56 UTC, Regan Heath wrote:
> On Tue, 17 Jul 2012 15:46:34 +0100, Jacob Carlborg <doob@me.com> wrote:
>
>> On 2012-07-17 16:36, Regan Heath wrote:
>>
>>> I believe old-style no parameter function declarations MUST have "void"
>>> i.e.
>>>
>>>     int foo(void);
>>
>> That is still the case, regardless of "style"?
>>
>>> They cannot read:
>>>
>>>     int foo();
>>>
>>> The latter MUST have parameters, we just can't tell what they are.
>>
>> Take a look at this:
>>
>> http://en.wikipedia.org/wiki/K%26R_C#KRC
>>
>> In that example none of the functions have any parameters declared and are not called with any arguments.
>
> K&R C did not allow you to declare arguments at all, according to the wiki:
>
> "Since K&R function declarations did not include any information about function arguments, function parameter type checks were not performed, although some compilers would issue a warning message if a local function was called with the wrong number of arguments, or if multiple calls to an external function used different numbers or types of arguments. Separate tools such as Unix's lint utility were developed that (among other things) could check for consistency of function use across multiple source files."
>
> So all K&R function declarations were <name>() with no parameters.
>
> R

K&R was more than that.

I guess most old timers here will agree with me that it was
not much more than glorified assembler in what concerns typing.

Much of the typing C has today, was actually brought in as part of the
ANSI C standardization process.

--
Paulo

July 17, 2012
On Tuesday, 17 July 2012 at 15:13:52 UTC, Regan Heath wrote:
> On Tue, 17 Jul 2012 15:50:27 +0100, Jacob Carlborg <doob@me.com> wrote:
>
>> On 2012-07-17 16:37, Regan Heath wrote:
>>
>>> All my googling for "old style" "variadic" etc returned the use of
>>> va_alist and va_dcl so I can't see where/why Clang would do what it's
>>> doing.
>>
>> To be accurate it's the libclang function "clang_isFunctionTypeVariadic" that returns true.
>>
>> http://clang.llvm.org/doxygen/group__CINDEX__TYPES.html#ga343b2463b0ed4b259739242cf26c3ae2
>
> Is Clang open source, can we see the code for that function?  Perhaps it's a bug.. ANSI C may have made () without "void" obsolete, but no compiler I've ever used has actually enforced that - or perhaps C++ made old-style function definition/declarations obsolete and allowed () back again.
>
> R

In C++, a function with no parameters () is a synonym for (void).

--
Paulo
July 17, 2012
On Tue, Jul 17, 2012 at 08:07:08PM +0200, Paulo Pinto wrote:
> On Tuesday, 17 July 2012 at 15:16:56 UTC, Regan Heath wrote:
[...]
> >So all K&R function declarations were <name>() with no parameters.
> >
> >R
> 
> K&R was more than that.

This modern C declaration:

	int main(int argc, char **argv) {
		exit(1);
	}

is written thus in K&R:

	int main(argc, argv)
		int argc;
		char **argv;
	{
		exit(1);
	}


> I guess most old timers here will agree with me that it was not much more than glorified assembler in what concerns typing.
[...]

I guess you predate me. ;-) When I started learning C, it was already in the ANSI syntax, though there were enough K&R style code floating around that I've at least _seen_ K&R syntax. I'm guessing nowadays most people don't even know what K&R syntax is.


T

-- 
If I were two-faced, would I be wearing this one? -- Abraham Lincoln