关于函数指针的高级应用~求C库函数源代码
这几天我在学习C语言的过程中学到了函数指针这一个概念。我通过查阅各种资料、以及自己举出的几个例子,勉强知道了几个函数指针使用的优点。但是函数指针具体的应用、该在什么时候使用函数指针等方面的概念都很模糊!所以请教下谁能给个具体的关于函数指针使用的源代码了。
求C预言库函数源代码
typedef int (*Scanner)(void); static Scanner Scanners[256]; void SetupLexer(void) { int i; for (i = 0; i < END_OF_FILE + 1; i++) { if (IsLetter(i)) { Scanners[i] = ScanIdentifier; } else if (IsDigit(i)) { Scanners[i] = ScanNumericLiteral; } else { Scanners[i] = ScanBadChar; } } Scanners[END_OF_FILE] = ScanEOF; Scanners['\''] = ScanCharLiteral; Scanners['"'] = ScanStringLiteral; Scanners['+'] = ScanPlus; Scanners['-'] = ScanMinus; Scanners['*'] = ScanStar; Scanners['/'] = ScanSlash; Scanners['%'] = ScanPercent; Scanners['<'] = ScanLess; Scanners['>'] = ScanGreat; Scanners['!'] = ScanExclamation; Scanners['='] = ScanEqual; Scanners['|'] = ScanBar; Scanners['&'] = ScanAmpersand; Scanners['^'] = ScanCaret; Scanners['.'] = ScanDot; Scanners['{'] = ScanLBRACE; Scanners['}'] = ScanRBRACE; Scanners['['] = ScanLBRACKET; Scanners[']'] = ScanRBRACKET; Scanners['('] = ScanLPAREN; Scanners[')'] = ScanRPAREN; Scanners[','] = ScanCOMMA; Scanners[';'] = ScanSEMICOLON; Scanners['~'] = ScanCOMP; Scanners['?'] = ScanQUESTION; Scanners[':'] = ScanCOLON; if (ExtraKeywords != NULL) { char *str; struct keyword *p; FOR_EACH_ITEM(char*, str, ExtraKeywords) p = keywords_; while (p->name) { if (strcmp(str, p->name) == 0) { p->len = strlen(str); break; } p++; } ENDFOR } }