Inconsistent use of const qualifier between declaration and definition

后端 未结 2 1706
别跟我提以往
别跟我提以往 2020-12-03 05:44

I noticed that it\'s possible to have const qualifier on a value argument present in the function declaration and then omitted in the definition. That doesn\'t

2条回答
  •  眼角桃花
    2020-12-03 06:01

    This is a bug because it prevents legitimate code like:

    /* API declaration */
    void f(int);
    
    
    /* Implementation */
    void f(const int x) /* my business: x is my local var and I want it const */
    {
    }
    

    I can't believe anyone would code out of their way to diagnose this as a problem.

    Incidentally, GCC, which doesn't complain about this, used to have a warning about this situation. Perhaps it still does:

    void f(int func_ptr(void));
    
    void f(int (*func_ptr)(void))
    {
    }
    

    This is purely a stylistic inconsistency that doesn't serve a purpose, though.

提交回复
热议问题