code consistency, usage of typedef and struct

Asked by Andrius Bentkus

While analyzing the code I encountered some strange usage of "struct in6_addr" and "in6_addr_t".
A good example can be found in the function at
At the first glance it looks like these 2 sizeof macros should return different values, but they don't, since in6_addr_t is just a typedef of "struct in6_addr". Technically this is equivalent code, but it makes reading the code a little bit awkward.

I looked into the usage of typedefs and there are few reasons why typedefs should be used, the main 2 ones are: make code more readable or make it more portable.

The readability between "struct in6_addr" and "in6_addr_t" doesn't differ too much, since the struct definition is rather small. Furthermore, one of the linux kernel hackers, Greg Kroah-Hartman, strongly recommends to use typedef only for function prototype declarations. I analyzed the usage of both in the hipl code basis and there are about 3400 occurrences of "struct in6_addr" and just 300 of the typedef keyword.

Now from the *portability point of view*: I have looked up the linux kernel code, and there is not even one typedef in the network stack for internet address structures. This means that using just "struct in6_addr" should be portable, since the linux kernel can be ported on various machines.

All in all, I strongly recommend to avoid the in6_addr_t typedef and actually get rid of it as soon as possible.

So, my actual question to you guys is, should there be a convention to avoid unnecessary typedef usage in the code and switch to a more consistent usage, _especially_ in the same codeblock (take a look at the link provided at the beginning)?

Question information

English Edit question
HIPL Edit question
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Miika Komu (miika-iki) said :

While I think a typedef for struct in6_addr is ok, I think it should be used more consistently. The 300-3400 ratio you mentioned is unjustifiable. I would suggest changing it to 0-3700 in favor of "struct in6_addr". Any comments from others?

Revision history for this message
Tobias Heer (heer) said :

I agree. Skip the typedef. Good catch, Andrius!

Revision history for this message
Diego Biurrun (diego-biurrun) said :

Such typedefs are evil and a sign of bad style - no wonder is full of them. In general typedefs should be used sparingly. Your instinct to trust kernel hackers before HIPL hackers on the subject is spot-on.

Can you help with this problem?

Provide an answer of your own, or ask Andrius Bentkus for more information if necessary.

To post a message you must log in.