const int *p vs. int const *p - Is const after the type acceptable?

前端 未结 15 1706
萌比男神i
萌比男神i 2020-12-08 05:01

My co-worker is 0 for 2 on questions he has inspired (1, 2), so I thought I\'d give him a chance to catch up.

Our latest disagreement is over the style issue of wher

15条回答
  •  不知归路
    2020-12-08 05:13

    People typically use const int* blah because it reads well as English. I wouldn't underestimate the usefulness of that.

    I find that the int* const blah variation is rare enough that it's not typically useful to make the more common definition backwards. I am, in general, not a fan of anything that even slightly obscures code in the general case, though it might provide some nominal benefit in the exceptional case.

    See also "if (1 == a)". Some people really enjoy writing code that doesn't read as English. I am not one of those people.

    Really, though, the rules behind const are simple. Look to the left, then to the right. So simple that I wouldn't think it's worth much attention in a style guide.

提交回复
热议问题