é¢æ°ã®ã¢ãã¬ã¹ã¨ãã¤ã³ã¿
ï¼£è¨èªç·¨ã第ï¼ï¼ç« ãé¢æ°ãã¤ã³ã¿
http://www.geocities.jp/ky_webid/c/043.html
pã¨ããååã®é¢æ°ãã¤ã³ã¿ã«ãmyabsé¢æ°ã®ã¢ãã¬ã¹ãä»£å ¥ããã«ã¯ã
p = myabs;
ã¨ããã ãã§ãã次ã«ãé¢æ°ãã¤ã³ã¿ããé¢æ°ãå¼ã³åºãæ¹æ³ã§ãããããã«ã¯ï¼éãã®æ¹æ³ãããã¾ãã
ans = (*p)(-100); /* myabs(-100); ã¨ããå¼ã³åºãã¨åãçµæ */
ã¾ãã次ã®ããã«æ¸ããã¨ãã§ãã¾ãã
ans = p(-100); /* myabs(-100); ã¨ããå¼ã³åºãã¨åãçµæ */
å¾è ã®æ¹æ³ã§ã¯ãé¢æ°ãã¤ã³ã¿ããåç §ã«ãã£ã¦é¢æ°ãå¼ãã§ããã®ããããã¨ãpé¢æ°ã¨ããé¢æ°ãå¼ã㧠ããã®ããåããã«ãããªãã¾ããéããã¯ã£ãããããããã«ãåè ã®æ¹æ³ã使ããã¨ãå¤ãããã§ãã
ãªãã§*pã¨pã®ã©ã£ã¡ã§ãããã®ãçåã«æã£ãã®ã§ã¡ãã£ã¨å®é¨
#include<stdio.h> foo(){ puts("foo"); } main(){ printf("%d\n",foo); printf("%d\n",*foo); printf("%d\n",**foo); printf("%d\n",&foo); foo(); (*foo)(); (**foo)(); (&foo)(); }
å®è¡çµæ
$ ./a.out 8014 8014 8014 8014 foo foo foo foo
ãªãã¨ããã¹ã¦åãå¤ã ã£ãã
é¢æ°åã®å¤æ°(?)ã«ã¯èªåèªèº«ã®ã¢ãã¬ã¹ãå
¥ã£ã¦ããã®ãã