Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: David Brown Newsgroups: comp.lang.c Subject: Re: question about linker Date: Sun, 1 Dec 2024 14:50:40 +0100 Organization: A noiseless patient Spider Lines: 47 Message-ID: References: <877c8nt255.fsf@nosuchdomain.example.com> <20241129142810.00007920@yahoo.com> <20241129161517.000010b8@yahoo.com> <87mshhsrr0.fsf@nosuchdomain.example.com> <8734j9sj0f.fsf@nosuchdomain.example.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Sun, 01 Dec 2024 14:50:41 +0100 (CET) Injection-Info: dont-email.me; posting-host="cb92292cff9a7aed5107a3020cf78af5"; logging-data="2671105"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18R+2lwdsDBDhM2qR03s9kqu6ok+ZdwLco=" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:cXuDkc+L/vpnw1WMAcWk0hLKJ0k= Content-Language: en-GB In-Reply-To: Bytes: 3702 On 30/11/2024 01:55, Waldek Hebisch wrote: > Keith Thompson wrote: >> Bart writes: >>> It's another point of confusion. In my language I don't treat function >>> declarations like variable declarations. A function is not a >>> variable. There is no data storage associated with it. >> >> In C, declarations can declare objects, functions, types, etc. I fail >> to see how your language is relevant. >> >>> In C it is unfortunate, as it makes it hard to trivially distinguish a >>> function declaration (or the start of a function definition) from a >>> variable declaration. >> >> It's not as hard as you insist on pretending it is. A function >> declaration includes a pair of parentheses, either empty or >> containing a list of parameters or parameter types. >> >> Function declarations outside header files are valid, but tend to be >> rare in well-written C code. > > Hmm, in well-written code static functions are likely to be a > 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? > Without doubt, most functions (and non-local data) should be static. 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. 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. 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.