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;
    }


  • 相关阅读:
    Datax streamreader json测试样例
    dbeaver 连接 elasticsearch 记录
    灾害链开发记录资料汇总
    mxgraph
    drawio www.diagrams.net 画图应用程序开发过程资料汇总
    neo4j学习记录
    GraphVis 图可视化分析组件
    D3学习记录
    Kubernetes K8S之固定节点nodeName和nodeSelector调度详解
    记一次性能优化,单台4核8G机器支撑5万QPS
  • 原文地址:https://www.cnblogs.com/smartvessel/p/2028466.html
Copyright © 2011-2022 走看看