这是优雅还是变态?

看了一个C源代码,这个C的lib广泛引用在包括firefox等很多地方

看到如下的代码,百思不解

static   int  PTRCALL
PREFIX(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 < iostream >
#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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值