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

前端 未结 15 1674
萌比男神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:31

    Let me put my 2¢ into the discussion.

    In modern C++ I'd recommend to stick to int const instead of const int to highlight the difference between const and constexpr. It would help programmer to remember that const int cannot be always thought as compile-time constant, because:

    • compiler may (will?) allocate memory for it,
    • this memory may even be not write-protected (stack segment),
    • such a constant cannot serve all the duties constexpr can.

提交回复
热议问题