在 C 中编写大型函数声明有很多约定。以下是一些最常见的约定:
/////////////////////////////
// Type // Meaning ///
/////////////////////////////
// `.` // Single space //
// `-|` // Half an indent //
// `->` // Full indent //
/////////////////////////////
// One line
static inline int namespace_class_method(class_t *self, a_t a, b_t b, c_t c);
// Traditional C
static inline int namespace_class_method(self, a, b, c)
..class_t *self;
..a_t a;
..b_t b;
..c_t c;
{
../* Traditional K&R C had no declarations */
}
// Line wrapping
static inline int namespace_class_method(class_t *self, a_t a,
b_t b, c_t c);
// Naive
static inline int namespace_class_method(class_t *self, a_t a,
--->b_t b, c_t c);
// Linux, VIM[1]
static inline int namespace_class_method(class_t *self, a_t a,
........b_t b, c_t c);
// GNU
static inline int
namespace_class_method(class_t *self, a_t a,
.......................b_t b, c_t c);
// Java[2]
static inline int
namespace_class_method
-|(
--->class_t *self,
--->a_t a,
--->b_t b,
--->c_t c
-|);
// Haskell style
static inline int
namespace_class_method
-|( class_t *self
-|, a_t a
-|, b_t b
-|, c_t c );
选择一个并坚持下去。一致性和可读性比宗教和风格更重要。
[1]:cindent,默认为 C/C++ 开启。
[2]:不确定它是在 Java、JavaScript 还是其他地方,但我之前已经看到过这个被广泛使用。