Liste des Groupes | Revenir à cl c |
On 01/12/2024 11:34, David Brown wrote:In a different context, yes - they can all be used in expressions of the form "a[i]". Different context, different relationship.
"int", "void" and "double" are totally different types in my view. "int", "pointer to int", "array of int", "function returning int" all have a relation that means I would not describe them as /totally/ different types - though I would obviously still call them /different/ types.What about 'array of int', 'array of double' and 'array of void*'; do they have a relation too?
>
Your examples, expressed left-to-right, happen to share the last element. They could also share other elements; so what?All I was saying is that it is wrong to say a single declaration can have identifiers of /totally/ different types - the types you are allowed to use in one declaration have a very clear relationship with each other.
It's not something I find to be a noticeable issue. I prefer, on the whole, to avoid forward declarations - I like to order by code so that functions are defined before they are called. It makes it easier to see the structure of the code and call trees. There are exceptions when I feel a different order is clearest, but those are rare and I can put up with writing static function declarations in those cases. (For non-static functions, there is invariably a declaration in a matching header file.)That's a separate problem. But without forward declarations, at some point you're going to add some expression in the middle of the file, but find you're calling a function which is declared later on in the file rather than earlier.Function declarations outside header files are valid, but tend to be>
rare in well-written C code.
>
A function definition - as typically written - is also a function declaration. So presumably you mean non-defining declaration here.
>
Some people have a style where they write forward declarations of all functions defined in a C file near the top of the file. I am not a fan of that myself - especially as over time, this redundant information is rarely kept fully in sync with the rest of the code.
That's not something you want to waste time thinking about.
Les messages affichés proviennent d'usenet.