Deutsch   English   Français   Italiano  
<vihhkj$2er60$1@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: David Brown <david.brown@hesbynett.no>
Newsgroups: comp.lang.c
Subject: Re: question about linker
Date: Sun, 1 Dec 2024 12:34:41 +0100
Organization: A noiseless patient Spider
Lines: 189
Message-ID: <vihhkj$2er60$1@dont-email.me>
References: <vi54e9$3ie0o$1@dont-email.me> <vi6sb1$148h7$1@paganini.bofh.team>
 <vi6uaj$3ve13$2@dont-email.me> <87plmfu2ub.fsf@nosuchdomain.example.com>
 <vi9jk4$gse4$1@dont-email.me> <vi9kng$gn4c$1@dont-email.me>
 <87frnbt9jn.fsf@nosuchdomain.example.com> <viaqh0$nm7q$1@dont-email.me>
 <877c8nt255.fsf@nosuchdomain.example.com> <viasv4$nm7q$2@dont-email.me>
 <vibr1l$vvjf$1@dont-email.me> <vic73f$1205f$1@dont-email.me>
 <20241129142810.00007920@yahoo.com> <vicfra$13nl4$1@dont-email.me>
 <20241129161517.000010b8@yahoo.com> <vicque$15ium$2@dont-email.me>
 <vid110$16hte$1@dont-email.me> <87mshhsrr0.fsf@nosuchdomain.example.com>
 <vidd2a$18k9j$1@dont-email.me> <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 12:34:44 +0100 (CET)
Injection-Info: dont-email.me; posting-host="cb92292cff9a7aed5107a3020cf78af5";
	logging-data="2583744"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1/Twsf5WRNiJyp1ixJatIKq6YPWiAdGjHs="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:AaGlu4TjbInI6BNKesEXH5dUQTE=
In-Reply-To: <8734j9sj0f.fsf@nosuchdomain.example.com>
Content-Language: en-GB
Bytes: 9932

On 30/11/2024 00:44, Keith Thompson wrote:
> Bart <bc@freeuk.com> writes:
>> On 29/11/2024 20:35, Keith Thompson wrote:
>>> Bart <bc@freeuk.com> writes:
>>> [...]
>>>> C's syntax allows a 14-parameter function F to be declared in the same
>>>> statement as a simple int 'i'.
>>> Yes (except that it's a declaration, not a statement) :
>>>       int i = 42, F(int, int, int, int, int, int, int,
>>>                     int, int, int, int, int, int, int);
>>> Are you under the impression that anyone here was not already aware
>>> of
>>> that?  Would you prefer it if the number of parameters were arbitrarily
>>> restricted to 13?
>>> Do you think that anyone would actually write code like the above?
>>> C generally doesn't impose arbitrary restrictions.  Because of that,
>>> it's possible to write absurd code like the declaration above.  99% of
>>> programmers simply don't do that, so it's not a problem in practice.
>>>
>>>> I'd say that F and i are different types! (Actually I wouldn't even
>>>> consider F to be type, but a function.)
>>> Neither F nor i is a type.  i is an object (of type int), and F is a
>>> function (of type int(int, int, int, int, int, int, int, int, int, int,
>>> int, int, int, int)).
>>>
>>>> That F(1, 2, 3.0, "5", "six", seven, ...) might yield the same type as
>>>> 'i' is irrelevant here.
>>> It's relevant to the syntax.  i and F can be declared in the same
>>> declaration only because the type of i and the return type of F happen
>>> to be the same.  If F returned void, i and F would have to be declared
>>> separately.
>>> Which, of course, is a good idea anyway.
>>> You're posting repeatedly trying to convince everyone that C allows
>>> ridiculous code.  We already know that.  You are wasting everyone's time
>>> telling us something that we already know.  Most of us just don't obsess
>>> about it as much as you do.  Most of us recognize that, however
>>> convoluted C's declaration syntax might be, it cannot be fixed in a
>>> language calling itself "C".
>>> Most of us here are more interested in talking about C as it's
>>> specified, and actually trying to understand it, than in complaining
>>> about it.
>>>
>>>> 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!
>>> No, the object D unambiguously has type int[3][4][5]
>>
>> (So it would have a different type from E declared on in the same
>> declaration:
>>
>>     int D[3][4][5], E;
>>
>> ? In that case tell that to David Brown!)
> 
> Yes, of course D and E have different types.  I'm certain he's
> aware of that.

Yes, I am.  (I know you wisely dislike speaking for other people, but 
you are pretty good at it!)

> 
> I wrote that the object D is unambiguously of type int[3][4][5], and the
> expression D can be of the array type int[3][4][5] or of the pointer
> type int(*)[3][4], depending on the context.  Do you agree?  Or do you
> still claim that D can have any of "4 or 5 possible types"?
> 
> (Note that I'm not talking about the type of the expression D[i] or of
> any other expression that includes D as a subexpression.)
> 
>> You seem have missed the point of my post, which was a reply to
>> David's remark that 'they can't have totally different types' which
>> was in response to my saying that each variable in the same
>> declaration can 'be [of] a totally different type'.
> 
> David apparently has a different definition of "totally different types"
> than you do.  Since the standard doesn't define that phrase, I suggest
> not wasting time arguing about it.
> 

"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.

The syntax of C allows one declaration statement to declare multiple 
identifiers of types related in this way - it does not allow declaration 
of types of /totally/ different types.

That was the point I was trying, and clearly failing, to explain to Bart.


> Given:
>      int D[3][4][5], E;
> the object D is of type int[3][4][5], and E is of type int.  Do you
> understand that?
> 
> If you wanted to change the type of D from int[3][4][5] to
> double[3][4][5], you'd have to use two separate declarations.
> Do you understand that?  (Of course you do, but will you admit that
> you understand it?)
> 
> I think that distinction is what David had in mind.  double[3][4][5] and
> int are "totally different types", but int[3][4][5] and int are not.
> Entities of "totally different types" cannot be declared in a single
> declaration.  You don't have to accept that meaning of the phrase (which
> I find a bit vague), but it's clearly what David meant.

It is certainly a vague term - there is no well-defined difference 
between "totally different types" and "different types".  But since Bart 
specifically called them /totally/ different types, the only way I could 
interpret that is suggesting that they could be any types at all.  And 
as we all know (even Bart, though he seems determined to feign 
ignorance), multiple identifiers in the same declaration cannot be of 
completely independent types.

> 
> The point is that there are restrictions on what can be combined into a
> single declaration.  But these days it's usually considered good style
> to declare only one identifier in each declaration, so while this :
>      int i, *p;
> is perfectly valid, and every C compiler must accept it, this :
>      int i;
>      int *p;
> is preferred by most C programmers.
> 
> Do you understand that?
> 
>> DB is assuming the type of the variable after it's been used in an
>> expression that is fully evaluated to yield its base type. So my
>> A[100] is used as A[i], and D[3][4][5]  is used as D[i][j][k].

I was trying to explain that this the principle C syntax uses - "A" and 
"D" have different types, but expressions of the same format as used in 
the common declaration have a common type.

>>
>> But of course they may be evaluated only partially, yielding a range
>> of types.
> 
> What "range of types" do you think D can have?
> 
>>> Would you write "const int F();"?  Or would you omit the "const"?  How
>>> does the fact that "const" is allowed inconvenience you?
>>
>> 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.
========== REMAINDER OF ARTICLE TRUNCATED ==========