[Swan-dev] static things in headers
D. Hugh Redelmeier
hugh at mimosa.com
Wed Sep 6 15:38:32 UTC 2017
Perhaps I'm old fashioned but we have avoided putting static things in
headers.
- they notionally take resources in every compilation unit that includes
the header. (But smart compilers can eliminate unused instances.)
- .h files are about sharing and static things are not shared
Exception: inline functions. An inline function is useful as a cleaner
replacement for macros. If I remember correctly, making an inline
function static makes the semantics simpler allowing a compiler to do
a better job.
Currently the only exceptions I see are:
linux/include/des/podd.h:59:static const unsigned char odd_parity[256] = {
linux/include/des/sk.h:59:static const DES_LONG des_skb[8][64] = {
osxApp/MainMenuController.h:20:static AuthorizationRef gAuth;
include/ietf_constants.h:1696:static const unsigned char sha1_rsa_oid_blob[ASN1_SHA1_RSA_OID_SIZE] = {0x30,0x0d,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x01,0x05,0x05,0x00};
include/ietf_constants.h:1698:static const uint8_t len_sha1_rsa_oid_blob[ASN1_LEN_ALGO_IDENTIFIER] = {ASN1_SHA1_RSA_OID_SIZE};
The first three are in imported code and should not be changed. The second
two, in my opinion, ought to be eliminated (definitions moved).
The objects defined in last two are only actually used one place so
there is probably no serious consequence to the current code.
More information about the Swan-dev
mailing list