On 21.02.24 19:56, Edward Welbourne via Development wrote:
Andre' Poenitz <[email protected]> (21 February 2024 19:21) wrote:1. 'static' is attached to individual functions, not a scope of uncertain extend. When working on unfamiliar code it helps to understand the context. With 'static' the locality is obvious in the immediate context of the function and not set by some 'namespace {' potentiall a dozen functions and hundreds of lines of code away.In particular this means that if someone picks up the function and moves it elsewhere in the file, cut and paste, it's very easy to fail to notice that they've moved it out of a nameless namespace and thereby suddenly made it visible to the linker. They'd have taken that little word "static" on the front of the declaration with it, if it'd been there, because it's not so easy to miss. (Incidentally, the ways I can think of to say "has no name" tend to suffer from some degree of precedent as "has a name but it has not been disclosed" - the anonymous author of a pamphlet, the unnamed person who reported a problem. I'm currently unable to think of such a precedent for "nameless", but I suspect that's only that I can't currently think of it. Then again, if a namespace with no name actually does have a secret name, I guess that just matches the linguistic baggage.)
There is a warning for a missing prototype/declarations(-Wmissing-prototypes and -Wmissing-declarations). The clang code model in QtCreator is warning me reliable about it. You can even enforce it by -Werror if you like. ;-)
Anonymous namespace have an other advantage. They work with other construct like classes, enumerations etc. too. People tend to copy code and then you end with a slightly different class. We already had ODR problems because it. And this bugs are hard to find. If you put everything in an anonymous namespace you are simply fine. It is a very easy rule. Yes, that should be not happen but it does.
-- Development mailing list [email protected] https://lists.qt-project.org/listinfo/development
