What is this syntax?

S

Steve

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?

Thanks
 
G

Geoff

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?

Thanks

It declares the functions as extern void, exactly as you can declare
variables like:

int integer1, integer2;

extern void sendout(float),flush();

is equal to:

extern void sendout(float);
extern void flush();

Short-hand like this is generally frowned upon since you have to track
down these declarations and fix them if you need to make a change.
Best practice is one declaration, one line - for variables and
functions.
 
S

Steve

It declares the functions as extern void, exactly as you can declare
variables like:

int integer1, integer2;

extern void sendout(float),flush();

is equal to:

extern void sendout(float);
extern void flush();

Short-hand like this is generally frowned upon since you have to track
down these declarations and fix them if you need to make a change.
Best practice is one declaration, one line - for variables and
functions.

Thanks Geoff, I wasn't aware you could list functions like that.
I'd inadvertently always used best-practice, that's a first!
 
S

Seebs

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.
Yup.

Is this correct C syntax, and if so, any ideas what it signifies?

What do you make of:

int i, j;

How about:
int a[10], b[10];

How about:
int foo(void), bar(void);
?

-s
 
S

Steve

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.
Yup.

Is this correct C syntax, and if so, any ideas what it signifies?

What do you make of:

        int i, j;

How about:
        int a[10], b[10];

How about:
        int foo(void), bar(void);
?

-s

Thanks Peter, got it :)
 
A

Andrey Tarasevich

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top