关于常量:参数传递中const位置的c标准是什么?

What's the c++ standard in const postion in parameter passing?

如果我没记错,请使用以下函数参数:

1
2
void foo(const Type& type);
void foo(Type const& type);

是等效的。声明它们的标准方法是什么?
通过使用第一个还是第二个函数声明?
如果ISO C没有定义任何规范,则"标准"是最易读和使用最多的版本。


What is the standard way to declare them?

两者都是标准。

With"standard" I mean the most readable and used version

可读性在情人眼中。我喜欢第二个,因为它给出了从右到左的一致顺序。有些人更喜欢第一种,因为它明确地将限定词与它限定的类型相关联。


没有普遍接受的C风格指南。我能想到的最接近的是Google的C指南,他们在这个主题上要说的是...

Some people favor the form int const foo to const int foo. They argue that this is more readable because it's more consistent: it keeps the rule that const always follows the object it's describing. However, this consistency argument doesn't apply in codebases with few deeply-nested pointer expressions since most const expressions have only one const, and it applies to the underlying value. In such cases, there's no consistency to maintain. Putting the const first is arguably more readable, since it follows English in putting the"adjective" (const) before the"noun" (int).

That said, while we encourage putting const first, we do not require it. But be consistent with the code around you!