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


  • 相关阅读:
    反向代理实例
    nginx常用命令和配置
    nginx的安装
    Can Live View boot up images acquired from 64bit OS evidence?
    What is the behavior of lnk files?
    EnCase v7 search hits in compound files?
    How to search compound files
    iOS 8.3 JB ready
    Sunglasses
    现代福尔摩斯
  • 原文地址:https://www.cnblogs.com/smartvessel/p/2028466.html
Copyright © 2011-2022 走看看