Protype form I hav'nt seen before 
Author Message
 Protype form I hav'nt seen before

Just a quick question, is the following part of the c standard, and if
so what (if anything) is said about it?

void a ( int )
{
        //do a

Quote:
};

void b ( int )
{
        //do b

Quote:
};

void c ( int )
{
        //do c

Quote:
};

void d ( int )
{
        //do d

Quote:
};

void e ( int )
{
        //do e

Quote:
};

void f ( int )
{
        //do f

Quote:
};

void g ( int )
{
        //do g

Quote:
};

void h ( int )
{
        //do h

Quote:
};

void ( * foo [ 8 ] ) ( int ) =
{
        a, b, c, d, e, f, g, h
Quote:
};

--



Wed, 03 Mar 2004 03:42:20 GMT  
 Protype form I hav'nt seen before


Quote:
>Just a quick question, is the following part of the c standard, and if
>so what (if anything) is said about it?

Well apart from the first 8 semicolons :( what is worrying you.

Quote:

>void a ( int )
>{
>       //do a
>};

>void b ( int )
>{
>       //do b
>};

>void c ( int )
>{
>       //do c
>};

>void d ( int )
>{
>       //do d
>};

>void e ( int )
>{
>       //do e
>};

>void f ( int )
>{
>       //do f
>};

>void g ( int )
>{
>       //do g
>};

>void h ( int )
>{
>       //do h
>};

>void ( * foo [ 8 ] ) ( int ) =
>{
>       a, b, c, d, e, f, g, h
>};

Francis Glassborow
I offer my sympathy and prayers to all those who are suffering
as a result of the events of September 11 2001.
--



Thu, 04 Mar 2004 06:15:15 GMT  
 Protype form I hav'nt seen before

Quote:

> Just a quick question, is the following part of the c standard, and if
> so what (if anything) is said about it?

> void a ( int )

This is an error.  The parameters in a function definition must
have names.

Quote:
> {
>    //do a
> };

The semicolon here may be an error (can't be bothered to look it
up right now) and is certainly not needed.

Quote:
> [...]
> void ( * foo [ 8 ] ) ( int ) =
> {
>    a, b, c, d, e, f, g, h
> };

This looks okay to me and cdecl agrees:

    blp:~(0)$ cdecl
    Type `help' or `?' for help
    cdecl> explain void ( * foo [ 8 ] ) ( int );
    declare foo as array 8 of pointer to function (int) returning void
    cdecl>

What problem did you anticipate?
--



Thu, 04 Mar 2004 06:15:17 GMT  
 Protype form I hav'nt seen before

Quote:

> Just a quick question, is the following part of the c standard,
> and if so what (if anything) is said about it?

It isn't *part* of the C standard, but could be part of a
strictly conforming program.  What do you think is wrong
with it?
--



Thu, 04 Mar 2004 06:15:22 GMT  
 Protype form I hav'nt seen before

Quote:
>Just a quick question, is the following part of the c standard, and if
>so what (if anything) is said about it?

>void a ( int )
>{
>    //do a
>};

Standard C does not allow unnamed parameters in function definitions.

Dan
--
Dan Pop
CERN, IT Division

Mail:  CERN - IT, Bat. 31 1-014, CH-1211 Geneve 23, Switzerland
--



Thu, 04 Mar 2004 06:15:25 GMT  
 Protype form I hav'nt seen before
Quote:

> Just a quick question, is the following part of the c standard, and if
> so what (if anything) is said about it?

> void a ( int )
> {
>         //do a
> };

[etc..]

Quote:
> void ( * foo [ 8 ] ) ( int ) =
> {
>         a, b, c, d, e, f, g, h
> };

This isn't a prototype. It's a declaration of a variable named foo.  Foo
is an array of 8 pointers. Each pointer points to a function that takes
1 int argument and returns void. The 8 pointers are initially set to
point to functions a, b, c, etc.

In code, the array can be used as follows:

   int i = 3;

   (*foo[i])(10);       /* equivalent to d[10]; */

The * in the call is optional, so this may be written foo[i](10);
--



Thu, 04 Mar 2004 06:15:27 GMT  
 Protype form I hav'nt seen before

Quote:

>Just a quick question, is the following part of the c standard, and if
>so what (if anything) is said about it?

>void a ( int )
>{
>    //do a
>};

[...etc...]
>void ( * foo [ 8 ] ) ( int ) =
>{
>    a, b, c, d, e, f, g, h
>};

It's not a prototype, it's a variable definition.  Read it from the
inside-out:

   foo[8]

"foo" is an array of 8...

   (*foo[8])

pointers...

   (*foo[8])(int)

functions taking a single int parameter...

   void (*foo[8])(int)

and returning void.

The initializer ({a,b,c,etc}) sets the initial value of the array
members to point to the specified functions.  E.g., foo[0] points to
the function a, foo[1] points to b, etc.  The syntax "foo[x](y)" will
call the function pointed to by foo[x] and pass the paramter y to that
funtion.  The syntax "(*foo[x])(y)" is equivalent.

If the values of foo (i.e., the functions pointed to) never change,
you might want to change the definition to

   void (* const foo[8])(int)

Which reads (inside-out again) "foo is an array of 8 const pointers to
functions taking a single int paramter reteurning void".

HTH.  Regards,

                               -=Dave
--
Change is inevitable, progress is not.
--



Thu, 04 Mar 2004 06:15:36 GMT  
 Protype form I hav'nt seen before
Quote:

> Just a quick question, is the following part of the c standard, and if
> so what (if anything) is said about it?

[similar function defs snipped]

Quote:
> void h ( int )
> {
>         //do h
> };

> void ( * foo [ 8 ] ) ( int ) =

Is this construct you're interested in?

Try cdecl:

cdecl> explain void ( * foo [ 8 ] ) ( int )
declare foo as array 8 of pointer to function (int) returning void

Quote:
> {
>         a, b, c, d, e, f, g, h
> };

This is an initialization with the pointers of the above defined
funtions.

HTH

Cesar
--



Thu, 04 Mar 2004 06:15:38 GMT  
 Protype form I hav'nt seen before

Quote:

>Just a quick question, is the following part of the c standard, and if
>so what (if anything) is said about it?

>void a ( int )
>{
>    //do a
>};

snip

>void ( * foo [ 8 ] ) ( int ) =
>{
>    a, b, c, d, e, f, g, h
>};

Other than the fact that each of your function definitions needs a
name for the parameter, such as void a (int aa), it all seems kosher
to me.  You are initializing a global array of function pointers with
the addresses of several different functions.

<<Remove the del for email>>
--



Thu, 04 Mar 2004 06:15:44 GMT  
 Protype form I hav'nt seen before

Quote:

> void a ( int )
> {
>    //do a
> };

The name of the parameter can be left out in C++ but not in C.
The trailing semicolon is an error in both, I think.

Quote:
> void ( * foo [ 8 ] ) ( int ) =
> {
>    a, b, c, d, e, f, g, h
> };

This defines an array "foo" that contains eight pointers to
functions that take an int argument and return void.
--



Thu, 04 Mar 2004 06:15:52 GMT  
 Protype form I hav'nt seen before

Quote:

> Just a quick question, is the following part of the c standard, and if
> so what (if anything) is said about it?

> void ( * foo [ 8 ] ) ( int ) =
> {
>    a, b, c, d, e, f, g, h
> };

Yes.

foo is an array 8 of pointers.  Each pointer points to a function
that accepts a single int parameter and returns void.

-- James
--



Thu, 04 Mar 2004 06:15:53 GMT  
 Protype form I hav'nt seen before

Quote:

>Just a quick question, is the following part of the c standard, and if
>so what (if anything) is said about it?

>void a ( int )
>{
>    //do a
>};

>void b ( int )
>{
>    //do b
>};

>void c ( int )
>{
>    //do c
>};

>void d ( int )
>{
>    //do d
>};

>void e ( int )
>{
>    //do e
>};

>void f ( int )
>{
>    //do f
>};

>void g ( int )
>{
>    //do g
>};

>void h ( int )
>{
>    //do h
>};

>void ( * foo [ 8 ] ) ( int ) =
>{
>    a, b, c, d, e, f, g, h
>};

        foo is an array of 8 function pointers which point to
a,b,c,d,e,f,g,h respectively.
--



Thu, 04 Mar 2004 06:15:56 GMT  
 Protype form I hav'nt seen before

Quote:

> Standard C does not allow unnamed parameters in function definitions.

Oops, I missed that.  The compiler should have warned about each of
the function definitions if it doesn't support that extension.
Otherwise, it ought to work..
--



Thu, 04 Mar 2004 14:37:19 GMT  
 Protype form I hav'nt seen before

Quote:

>Just a quick question, is the following part of the c standard, and if
>so what (if anything) is said about it?

>void a ( int )
>{
>    //do a
>};

>void b ( int )
>{
>    //do b
>};

>void c ( int )
>{
>    //do c
>};

>void d ( int )
>{
>    //do d
>};

>void e ( int )
>{
>    //do e
>};

>void f ( int )
>{
>    //do f
>};

>void g ( int )
>{
>    //do g
>};

>void h ( int )
>{
>    //do h
>};

>void ( * foo [ 8 ] ) ( int ) =
>{
>    a, b, c, d, e, f, g, h
>};

foo is an array of 8 pointers to functions taking an int
parameter and returniing a void result: standard part of the type
system -- the same as a jump or call table or vector in
assembler.

Thanks. Take care, Brian Inglis         Calgary, Alberta, Canada
--

    fake address                use address above to reply

                                                spam traps
--



Sat, 06 Mar 2004 00:54:59 GMT  
 Protype form I hav'nt seen before

Quote:

>Just a quick question, is the following part of the c standard, and if
>so what (if anything) is said about it?

<snip>

Thanks for all the replies, bit clearer now.

dave
--



Sat, 06 Mar 2004 10:19:34 GMT  
 
 [ 15 post ] 

 Relevant Pages 

1. refrencing a form's objects on another form

2. Who's seen the standard?

3. making #define's to be seen across files

4. why my Control methods can't be seen by outside

5. Seeing pre=processor's work

6. The most frustrating windows bug i've seen

7. Start a command without seeing the console and get the exe's return code

8. Connection Manager sees GPS but can't find on any of the COM ports

9. Do you hav WinZip(.Zip) Source?

10. 'calling' a web form

11. calling Watcom DLL's form other compilers EXE's

 

 
Powered by phpBB® Forum Software