[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c

What is this syntax?

petertwocakes

7/19/2011 7:35:00 AM

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
5 Answers

Geoff

7/19/2011 8:12:00 AM

0

On Tue, 19 Jul 2011 00:34:34 -0700 (PDT), Steve
<petertwocakes@googlemail.com> 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?
>
>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.

petertwocakes

7/19/2011 8:33:00 AM

0

On Jul 19, 9:11 am, Geoff <ge...@invalid.invalid> wrote:
> On Tue, 19 Jul 2011 00:34:34 -0700 (PDT), Steve
>
>
>
>
>
> <petertwoca...@googlemail.com> 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?
>
> >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.

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

Seebs

7/19/2011 11:04:00 PM

0

On 2011-07-19, Steve <petertwocakes@googlemail.com> 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.

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
--
Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam@seebs.net
http://www.seeb... <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/...(Scientology) <-- get educated!
I am not speaking for my employer, although they do rent some of my opinions.

petertwocakes

7/21/2011 5:55:00 AM

0

On Jul 20, 12:04 am, Seebs <usenet-nos...@seebs.net> wrote:
> On 2011-07-19, Steve <petertwoca...@googlemail.com> 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.
>
> 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
> --
> Copyright 2011, all wrongs reversed.  Peter Seebach / usenet-nos...@seebs.nethttp://www.seebs.net/... lawsuits, religion, and funny pictureshttp://en.wikipedia.org/wiki/...(Scientology) <-- get educated!
> I am not speaking for my employer, although they do rent some of my opinions.

Thanks Peter, got it :)

Andrey Tarasevich

7/21/2011 5:20:00 PM

0

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