Andrey Tarasevich
7/21/2011 5:20:00 PM
On 7/19/2011 12:34 AM, Steve wrote:
> Hi, In a header file for a DSP library I downloaded, I found the
> following lines:
>
> extern void sendout(float),flush();
> extern void setup_codec(int),key_down(),int_enable(),int_disable();
>
> It looks like a function declaration, then a comma, then one or more
> function names.
>
> I don't know if I've led a sheltered life, but I've never seen
> anything like this before.
>
> Is this correct C syntax, and if so, any ideas what it signifies?
In C language a declaration formally consists of a "common part" - type
descriptor - and a comma-separated list of individual declarators. You
can declare multiple variables in one declaration, which probably does
not surprise you. The very same way you can declare multiple functions
in one declaration.
You can even mix variable and function declarators in one declaration
extern int a, foo(int), c, *bar(void);
There's nothing extraordinary in it, even though it is not something one
would see very often.
One interesting side note related to this issue is that when you declare
multiple variables in one declaration, you can freely choose whether you
want to produce a definition or a non-defining declaration for each
variable. For example
extern int a = 1, b;
defines 'a', but doesn't define 'b'.
The natural thing to ask is whether something like this is possible with
functions. For example, one might expect that
extern void foo(void) {}, bar(void);
would define 'foo' and leave 'bar' declared but not defined. In reality
C does not allow this. Declarations with multiple declarators are
allowed to declare multiple functions, but not define any of them.
Functions must be defined individually, one by one.
--
Best regards,
Andrey Tarasevich