Skip to main content

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

code:
void (*signal(int, void (*fp)(int)))(int);
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.

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:

signal function passing int , pointer function passing int returning nothing (void) returning pointer function passing int returning nothing (void)
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.

here's example:

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; }
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.


Forum The Ubuntu Forum Community Ubuntu Specialised Support Development & Programming Programming Talk [SOLVED] clockwise spiral rule from c-faqs


Ubuntu

Comments

Popular posts from this blog

How to change text Component easybook reloaded *newbee* - Joomla! Forum - community, help and support

After Effect warning: A problem occurred when processing OpenGL commands

Preconditions Failed. - Joomla! Forum - community, help and support