zoukankan      html  css  js  c++  java
  • 这是优雅还是变态?

    看了一个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;
    }


  • 相关阅读:
    JVM 参数(转)
    redis 事务
    redis 命令
    Redis配置文件参数说明(转)
    zookeeper原理(转)
    数字证书原理 转载
    证书 签名 验签 实例
    SSL双向认证java实现 (转)
    详细介绍Java垃圾回收机制 转载
    Java Socket重要参数讲解 (转载)
  • 原文地址:https://www.cnblogs.com/smartvessel/p/2028466.html
Copyright © 2011-2022 走看看