Sujet : Re: question about linker
De : bc (at) *nospam* freeuk.com (Bart)
Groupes : comp.lang.cDate : 29. Nov 2024, 19:26:41
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vid110$16hte$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
User-Agent : Mozilla Thunderbird
On 29/11/2024 16:42, David Brown wrote:
On 29/11/2024 15:15, Michael S wrote:
On Fri, 29 Nov 2024 13:33:30 +0000
Bart <bc@freeuk.com> wrote:
>
* It allows a list of variable names in the same declaration to each
have their own modifiers, so each can be a totally different type
>
They can't have "totally different" types - they can have added indirection or array indicators, following C's philosophy of describing the type by how the variable is used:
int x, *y, z[10];
Thus "x", "*y" and "z[i]" are all of type "int".
C's syntax allows a 14-parameter function F to be declared in the same statement as a simple int 'i'.
I'd say that F and i are different types! (Actually I wouldn't even consider F to be type, but a function.)
That F(1, 2, 3.0, "5", "six", seven, ...) might yield the same type as 'i' is irrelevant here.
Usually, given these declarations:
int A[100]
int *B;
int (*C)();
people would consider the types of A, B and C to be array, pointer and function pointer respectively. Otherwise, which of the 4 or 5 possible types would you say that D has here:
int D[3][4][5];
It depends on how it is used in an expression, which can be any of &D, D, D[i], D[i][j], D[i][j][k], none of which include 'Array' type!
Here's another puzzler:
const int F();
why is 'const' allowed here? There is no storage involved. It's not as though you could write 'F = 0' is there was no 'const'.
C allows this, but I personally would be happier if it did not. As Michael says below, most serious programmers don't write such code.
It doesn't matter. If you're implementing the language, you need to allow it.
If trying to figure out why some people have trouble understanding, it's something to consider.
It's also something to keep in mind if trying to understand somebody else's code: are they making use of that feature or not?
So this is a wider view that just dismissing design misfeatures just because you personally won't use them.
With the kind of C I would write, you could discard everything after C99, and even half of C99, because the subset I personally use is very conservative.