[Swan-dev] proposal: "const struct ip_protocol" => "ip_protocol"

D. Hugh Redelmeier hugh at mimosa.com
Sun Oct 13 15:42:07 UTC 2019


We currently have
	struct ip_protocol {...};

As far as I can tell, all uses of it are of the form
	const struct ip_protocol

Why not
	typedef const struct {...} ip_protocol;

Then all uses should be changed appropriately (a sed script would do it).

That way the "const" could not be left off accidentally, the code becomes 
more concise, easier to fit on a line, easier to type, easier to read 
("chunking"), etc.  More importantly, I think that the code becomes easier 
to think about -- the power of abstraction.

BETTER:

Almost all uses would be of the form
	ip_protocol *

If instead, we define:
	struct ip_protocol {...};
	typedef const struct *ip_protocol;

then the table initialization can use "const struct ip_protocol" and all 
other uses get to eliminate the *.  This should make the use even simpler 
and less error prone.  A better abstraction all around.

This change might not be a simple sed operation (I haven't checked) but it 
should be easy to do it without introducing errors.

I propose to make this change if there are no serious objections.

It should be done when most code is at rest.  Can people tell me if they 
have code in-flight that would be affected?

Practical detail:

We can make the transition "hard" by naming the struct differently 
(perhaps "ip_protocol_").  That way unconverted code would fail to 
compile.  That would be my preference.

Perhaps an initial soft transition would be easier.  Then we could switch 
to hard after we think all in-flight code has landed.


More information about the Swan-dev mailing list