Question on coding style in networking code
Hello All,
First off, this is probably a straight C question, but here goes...
I was looking at the kernel code, and in protocol.c the protocol structures are
instansiated and filled. Now, I have seen/used the following syntax:
struct x y = { x, y, z };I have not seen the following:
struct x y = {
member1: x,
member2: y,
member3: z
};What is the deal with this? Does the second way have any advantage over the previous?
Thanks in advance,
Chuck
Quoted 7 lines · On Sun, 19 Aug 2001 [email protected] wrote:
struct x y = { member1: x, member2: y, member3: z };What is the deal with this? Does the second way have any advantage over the previous?
_Much_ easier to grep for. Less pain in the ass when fields are added/removed/ reordered.
For anything with many fields (usually method tables) it's more convenient. And no, it's not just networking - filesystem-related code, etc. uses it all over the place.
Thank you for the reply.
I absolutely agree that it is much easier to read and figure out what is
going on. You don't have to keep going back to the struct declaration to find out what the fields are.
Thanks again,
Chuck
Quoted 24 lines · Alexander Viro
Quoted 7 lines · On Sun, 19 Aug 2001 [email protected] wrote:
struct x y = { member1: x, member2: y, member3: z };What is the deal with this? Does the second way have any advantage over the previous?
_Much_ easier to grep for. Less pain in the ass when fields are added/removed/ reordered.
For anything with many fields (usually method tables) it's more convenient. And no, it's not just networking - filesystem-related code, etc. uses it all over the place.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Quoted 30 lines · [email protected] wrote:
Thank you for the reply.
I absolutely agree that it is much easier to read and figure out what is
going on. You don't have to keep going back to the struct declaration to find out what the fields are.Thanks again,
ChuckQuoted 19 lines · Alexander Viro
Quoted 7 lines · On Sun, 19 Aug 2001 [email protected] wrote:
struct x y = { member1: x, member2: y, member3: z };What is the deal with this? Does the second way have any advantage over the previous?
_Much_ easier to grep for. Less pain in the ass when fields are added/removed/ reordered.
For anything with many fields (usually method tables) it's more convenient. And no, it's not just networking - filesystem-related code, etc. uses it all over the place.
For large structures it is a pure joy to work with. Check out sched.h and the "task_struct" where many of the fields come and go with "CONFIG" options.
George