Re: [cc65] function pointer, fastcall

From: Ullrich von Bassewitz <uz1musoftware.de>
Date: 2008-08-31 10:22:00
On Sat, Aug 30, 2008 at 02:27:24AM -0400, Greg King wrote:
> But, those parentheses are how the C language names "function objects!"
> Therefore, the proper syntax must be:
>
>     void fastcall ()(int);

No. The parenthesis aren't the way how the C language names "function
objects". They're the normal way to change the precedence of the operators,
similar to

        (3 + 4) * 2

which says "execute '+' first, even if '*' has a higher precedence".

The problem when defining pointers to functions is that the parenthesis around
the parameter list binds tighter than '*' which denotes the pointer. So while

        int * P;

is a pointer to int,

        int * F(void);

is not a pointer to function returning int, but a function that returns a
pointer to int. We must use parenthesis to change precedence and force '*' to
be applied to the function, not to "int":

        int (*F)(void);

is a pointer to function returning int. The same syntax is used for arrays,
which is another proof that the parenthesis have nothing to do with functions.
The [] operator binds tighter than '*', so

        int * A[10];

is an array of 10 pointers to int. If we want to make it a pointer to an array
of ints, we must use parenthesis to override precedence rules:

        int (*A)[10];

Please note the similarity with "pointer to function" syntax.

> As far as a compiler is concerned, the "token" that is being qualified by
> "fastcall" is "(", not "*".

See above. The parenthesis has nothing to do with the function, it is only
used to adjust operator precedence. Because of this, the fastcall modifier
cannot be applied to it.

Regards


        Uz


-- 
Ullrich von Bassewitz                                  uz@musoftware.de
                                                  
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Sun Aug 31 10:23:03 2008

This archive was generated by hypermail 2.1.8 : 2008-08-31 10:23:05 CEST