Macro and function with same name

前端 未结 5 879
我在风中等你
我在风中等你 2020-12-01 15:00

I have the following code

#define myfunc(a,b) myfunc(do_a(a), do_b(b))

void myfunc(int a, int b)
{
  do_blah(a,b);
}
int main()
{
    int x = 6, y = 7;
             


        
5条回答
  •  半阙折子戏
    2020-12-01 15:45

    I see three possible solutions:

    • define your macro after function definition.

    • define, before the function definition, do_a() and do_b() such that they return their argument, and redefine them at your will after function definition

    • perform do_a() and do_b() inside the function:

      void myfunc(int a, int b)
      {
          do_blah(do_a(a),do_b(b));
      }
      

    I have a strong preference for the latter.

提交回复
热议问题