Search code examples
c++c++11gcchtonl

Macro htonl interpretes inner commas as parameter separator


This is a unusual error returned at compile time, only with some compiler parameters.

OK with g++ -std=c++11 -m64 -O3 -DNDEBUG

But with g++ -std=c++11 -m64 -Wall -g, this problem occurs:

macro "htonl" passed 7 arguments, but takes just 1

Code:

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

I'm not sure if the problem comes from the call of htonlor if it comes from my templated hasher.

Do you know how to solve that?

Other infos:

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

Solution

  • Add another pair of braces:

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