这是优雅还是变态?
看了一個C源代碼,這個C的lib廣泛引用在包括firefox等很多地方
看到如下的代碼,百思不解
static?int?PTRCALLPREFIX(scanComment)(const?ENCODING?*enc,?const?char?*ptr,
????????????????????const?char?*end,?const?char?**nextTokPtr)
{
??if?(ptr?!=?end)?{
????if?(!CHAR_MATCHES(enc,?ptr,?ASCII_MINUS))?{
??????*nextTokPtr?=?ptr;
??????return?XML_TOK_INVALID;
????}
?這函數定義,比較奇怪,突破我的知識范圍了。我反復查了源代碼,搞了一個多小時。
所有的一切都是宏定義
#ifndef?PTRCALL#define?PTRCALL
#endif
#ifndef?PREFIX
#define?PREFIX(ident)?ident
#endif
?
PREFIX(scanComment) =scanComment?
static int PTRCALL PREFIX(scanComment)(const ENCODING *enc, const char *ptr, const char *end, const char **nextTokPtr)其實就是
static int PTRCALL scanComment (const ENCODING *enc, const char *ptr, const char *end, const char **nextTokPtr)scanComment 是函數名。這宏定義不是變態嗎?有啥好出?自己也寫了個,看看這玩意
#include?<stdio.h>
#include?<stdlib.h>
#ifndef?PTRCALL
#define?PTRCALL
#endif
#ifndef?PREFIX
#define?PREFIX(ident)?ident
#endif
using?namespace?std;
typedef?struct?prefix?{
??const?char?*name;
??char?*binding;
}?PREFIX;
typedef?int?(PTRCALL?*SCANNER)(int?a);
static?int?PTRCALL?PREFIX(scanComment)(int?a)
{
????cout<<"ss";
}
int?main()
{
????PREFIX(scanComment)(2);
????return?0;
}
?
轉載于:https://www.cnblogs.com/smartvessel/archive/2011/04/25/2028466.html
總結
- 上一篇: 高性能分页
- 下一篇: Oracle笔记 十四、查询XML操作、