Liste des Groupes | Revenir à cl c |
On 30/11/2024 01:55, Waldek Hebisch wrote:
I have a tool that translates C programs to my syntax. Most functions of codebases I tried are marked 'global', because the C version did not use 'static'.Hmm, in well-written code static functions are likely to be aWithout doubt, most functions (and non-local data) should be static.
majority. Some people prefer to declare all functions and
put declarations of static functions in the same file as the
functions itself. Conseqently, function declarations are not
rare in such code. Do you consider it well-written?
>
However, IMHO writing (non-defining) declarations for your static functions is a bad idea unless it is actually necessary to the code because you are using them in function pointers or have particularly good reasons for the way you order your code.A good reason might be NOT CARING how the code is ordered. I have to constantly keep that in mind when writing C programs. I don't like movings functions about after they've been written, it is easier to add a forward declaration, even though I'd rather not do that at all.
I don't find redundant declarations of static functions at all useful - and I find them of significant cost in maintaining files. It is far too easy to forget to update them when you change, delete or add new functions. And a list of such declarations that you don't feel you can trust entirely, is worse than useless.Why doesn't the compiler report a declaration that doen't match the definition?
Such lists might have been helpful to some people decades ago, when editors were more primitive. If I need a list of functions in a file (maybe it's someone else's code, or old code of mine), any programmer's editor or IDE will give me it - updated correctly in real-time, and not out of sync.Why isn't this a problem for exported/shared functions?
Les messages affichés proviennent d'usenet.