Shao Miller
5/30/2011 7:09:00 AM
On 5/29/2011 11:53 PM, luser- -droog wrote:
> On May 29, 12:16 pm, China Blue Angels<chine.b...@yahoo.com> wrote:
>> In article<irtr18$e0...@dont-email.me>, Shao Miller<sha0.mil...@gmail.com>
>> wrote:
>>
>>> On 5/29/2011 5:15 AM, adream307 wrote:
>>>> I want to declare a function like this:
>>>> (we named this type of function as F)
>>>> 1. the return type of F is "void"
>>>> 2. the parameter of F is a function pointer, this pointer point to a
>>>> function whose type is the same as F
>>>> can i declare a function like this
>>>> thank you
>>
>>> Perhaps you could make use of an obsolescent C construct[6.11.6p1]:
>>>
>>> #include <stdio.h>
>>>
>>> typedef void f_unspec();
>>> typedef void f_xxx(f_unspec *);
>>>
>>> f_unspec foo;
>>> f_xxx foo;
>>>
>>> void foo(f_xxx * func) {
>>> puts("foo()");
>>> if (func == foo) {
>>> puts("Called with self.");
>>> return;
>>> }
>>> func(func);
>>> return;
>>> }
>>>
>>> void bar(f_xxx * func) {
>>> puts("bar()");
>>> if (func == bar) {
>>> puts("Called with self.");
>>> return;
>>> }
>>> func(func);
>>> return;
>>> }
>>>
>>> int main(void) {
>>> foo(foo);
>>> foo(bar);
>>> bar(foo);
>>> bar(bar);
>>> return 0;
>>> }
>>
>> This is a known aspect of the C type system which becomes known to anyone who
>> understands
>> mode m = proc(m)void;
>>
>> This is similar to
>> mode m = struct(ref m field);
>> In C
>> typedef struct m{struct m *field;} m;
>>
>> The difference is in Algol 68 the reach of a declaration starts from the
>> beginning of the scope rather than its first declaration. That allows recursive
>> and forward declarations such as
>>
>> begin
>> proc yin = (S a)void: yang(y);
>> proc yang = (P b)void: yin(x(x));
>> P x, S y;
>> mode P = proc(P)P;
>> mode S = struct(ref S field);
>> skip
>> end
>>
>
> Wild!
> :)
Though I'm not 100% sure what that ("the reach") has to do with the C
code example... Maybe it doesn't and that's why the example was not
present in the response from "China Blue Angels". :)