Style question: procedure to read a variable

Hal Murray halmurray at sonic.net
Thu Jan 12 06:13:29 UTC 2023


I'm cleaning up ntp_control, the code in ntpd that supports ntpq.

My main goal is to make it easy to add new variables.

I'm setting things up so that each variable you might want to read needs one 
line in a table.  For the common data types, a macro will setup that line with 
reasonable type checking.

An obvious data type is a uint64_t for things like packet counts.

Part of the current code uses procedures to return a variable rather than just reading it.  If I was setting up an API, I'd probably do something like that.  But do we want/need that here?

The procedure means that the client can't write to the variable.  That's nice, but that isn't the type of error I'm worried about.  Should I be?  Is there any way to get c's type checking to make a variable read only (const) to outside world but writeable in the module that implements it?

In this case, I think we could setup a procedure to return a pointer to a const struct.

In this case, the variables are in a struct, so the client doesn't need to recompile when a new member is added to the struct.  But i/we recompile the whole world all the time so that's no an issue here.

>From my point of view, with my nose deep in the code, there is a nasty disadvantage.  Adding a new counter requires 2 more edits, one for the header file and one to setup the procedures.

Will anybody object if I remove those procedures?


-- 
These are my opinions.  I hate spam.





More information about the devel mailing list