[PATCH] CodingStyle update (was Re: URL to the latest /proc/driver/microcode)

From: James Manning (jmm@computer.org)
Date: Thu Feb 17 2000 - 20:49:17 EST


[ Thursday, February 17, 2000 ] Tigran Aivazian wrote:
> > +static struct file_operations microcode_fops = {
> > + write: microcode_write,
> > + open: microcode_open,
> > + release: microcode_release,
> > +};
> >
> > I'm guessing the above is a gcc extension to C of initializing a few
> > members of a structure? It's slightly confusing, but a stylistic choice.
> > (If it's standard C, I've never come across it before).
>
> it is a standard, called New Linux Kernel Coding Standard :)
>
> Didn't you know that after James Manning's patches were accepted, using
> structure name tags is the preferred way?

Good point Tigran... since it's officially preferred, it would appear to
be a good candidate for CodingStyle inclusion. What do you think?

James

--- linux-2.3.46/Documentation/CodingStyle Thu Feb 17 20:45:35 2000
+++ linux-2.3.46/Documentation/CodingStyle.new Thu Feb 17 20:43:07 2000
@@ -233,3 +233,26 @@
 stable. All options that are known to trash data (experimental write-
 support for file-systems, for instance) should be denoted (DANGEROUS), other
 Experimental options should be denoted (EXPERIMENTAL).
+
+
+ Chapter 8: Struct Initializations
+
+Struct initializations should use named syntax. It makes for cleaner,
+more compact, self-documenting and more readable code and allows later
+reordering of struct members (for example, to help cache behavior).
+It also allows new struct members to be introduced where they make the
+most sense (say, in the same cache line as other members they are likely
+to be access with).
+
+Since the official kernel compiler is gcc 2.7.2.3, that syntax is
+currently the preferred method. It is worth noting that C99 syntax
+(.field = initializer,) is also accepted by this compiler.
+
+struct struct_type foo = {
+ field1: initializer1,
+ field2: initializer2,
+ field3: initializer3,
+}
+
+The trailing comma on the last line allows for a homogenous look and easy
+rearrangement (eg for later blocking of some members in an #ifdef).

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Wed Feb 23 2000 - 21:00:20 EST