Thread: clockwise spiral rule from c-faqs
on link spiral rule given,
http://c-faq.com/decl/spiral.anderson.html
, example given in section 3 ultimate
even explanation given not able understand means.can 1 understand above code snippet evaluated , how can used.any example has kind of statement nice me understand.code:void (*signal(int, void (*fp)(int)))(int);
the reason it's called "the ultimate" because it's more complicated you're encounter (indeed, more complicated sane programmer use). author wanted demonstrate rule still worked on horribly complicated examples. declares article says does:
that is, "signal" function takes 2 arguments: first integer, , second function pointer named "fp". function pointer points function return type void, , argument integer. "signal" returns function pointer of same type.signal function passing int , pointer function passing int returning nothing (void) returning pointer function passing int returning nothing (void)
here's example:
signal takes integer (101) , pointer function (foo), prints integer gets, runs function gets argument 42, , returns function pointer (bar). then, in main, store function pointer, , run function refers argument 6667.code:#include <stdio.h> void foo(int a) { printf("a=%d\n", a); } void bar(int b) { printf("b=%d\n", b); } void (*signal(int i, void (*fp)(int)))(int) { printf("i=%d\n", i); fp(42); return bar; } int main(int argc, char **argv) { void (*fptr)(int) = signal(101, foo); fptr(6667); return 0; }
Forum The Ubuntu Forum Community Ubuntu Specialised Support Development & Programming Programming Talk [SOLVED] clockwise spiral rule from c-faqs
Ubuntu
Comments
Post a Comment