宏 htonl 将内部逗号解释为参数分隔符

Macro htonl interpretes inner commas as parameter separator

本文关键字:解释 参数 分隔符 htonl 内部      更新时间:2023-10-16

这是编译时返回的异常错误,仅使用某些编译器参数。

可以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 =  '', const char C2 =  '', 
         const char C3  = '', const char C4 =  '', const char C5 =  '', 
         const char C6  = '', const char C7 =  '', const char C8 =  '', 
         const char C9  = '', const char C10 = ''>
struct CompileTime
{
    //Do you think this code could help?
};

添加另一对大括号:

htonl((hash::CompileTime<'A', 'S', 't', 'r', 'i', 'n', 'g'>::hash))

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

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

为了解释为什么...这篇文章会有所帮助C/C++ 宏中的逗号

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