【问题标题】:Macro htonl interpretes inner commas as parameter separator [duplicate]宏 htonl 将内部逗号解释为参数分隔符
【发布时间】:2019-07-07 05:02:27
【问题描述】:

这是编译时返回的异常错误,只有一些编译器参数。

好的g++ -std=c++11 -m64 -O3 -DNDEBUG

但是使用g++ -std=c++11 -m64 -Wall -g,就会出现这个问题:

宏“htonl”传递了 7 个参数,但只需要 1 个

代码:

const unsigned int h = htonl(hash::CompileTime<'A', 'S', 't', 'r', 'i', 'n', 'g'>::hash);

我不确定问题是来自htonl 的调用还是来自我的模板化哈希。

你知道怎么解决吗?

其他信息:

template<const char C0,         const char C1 =  '\0', const char C2 =  '\0', 
         const char C3  = '\0', const char C4 =  '\0', const char C5 =  '\0', 
         const char C6  = '\0', const char C7 =  '\0', const char C8 =  '\0', 
         const char C9  = '\0', const char C10 = '\0'>
struct CompileTime
{
    //Do you think this code could help?
};

【问题讨论】:

    标签: c++ c++11 gcc htonl


    【解决方案1】:

    添加另一对大括号:

    htonl((hash::CompileTime&lt;'A', 'S', 't', 'r', 'i', 'n', 'g'&gt;::hash))

    【讨论】:

      【解决方案2】:

      一种解决方案是用额外的括号来帮助宏:

      const unsigned int h = htonl((hash::CompileTime<'A', 'S', 't', 'r', 'i', 'n', 'g'>::hash));
      

      解释原因...这篇文章会有所帮助 Comma in C/C++ macro

      这是宏内部的逗号解释问题。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-04-08
        • 1970-01-01
        • 2023-03-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多