c++compiler-errorsavr-gcc

macro passed 2 arguments, but takes just 1


my code didn't build successfully with this error message:

macro "hton_us" passed 2 arguments, but takes just 1

and it occurs on this line:

hton_us( &fi.size, 1 );

here is the refrence to hton_us

void hton_us( iu16 *us, iu8 num )
{
    iu16 local;

    while( num-- ) {
        local=*us;
        *us++=swap_us(local);
    }
}

I read in some similar question that told to use typedef but it didn't help me.


Solution

  • Using a little C preprocessor trick, you can skip the macro and just call the function:

    (hton_us)(&fi.size, 1);
    

    By surrounding hton_us in parentheses, it tells the compiler that this macro cannot be expanded, because it wasn't called with any args, and thus the function gets called instead.