Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #404010
| From | bartc <bc@freeuk.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: p = {1,0,0} |
| Date | 2026-11-02 22:58 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <11cb4hs$3a13l$1@dont-email.me> (permalink) |
| References | <11c7f1j$20b9h$1@dont-email.me> <11c7fj6$20gab$1@dont-email.me> <11cae5m$318tq$1@dont-email.me> <11calrt$34gq3$1@dont-email.me> <11carqs$36m0o$1@dont-email.me> |
On 02/11/2026 20:29, David Brown wrote:
> On 02/11/2026 19:47, bartc wrote:
>> On 02/11/2026 16:36, David Brown wrote:
>>> On 01/11/2026 14:41, bartc wrote:
>>>> On 01/11/2026 13:32, fir wrote:
>>>>> it is maybe banal but sometimes banal remarks also maybe should be
>>>>> stated as i dont remember if i even was posting on that
>>>>>
>>>>> the fact stat some cannot assign a structure like
>>>>> this
>>>>>
>>>>> s = {x,y};
>>>>>
>>>>> seems rather silly (especially as structures can be assigned/copied)
>>>>>
>>>>> with this {0,0,1} at least c has a basic of ths vector/tupple support
>>>>> and this 'native' support is quite standable..so its very weird it
>>>>> is 'blocked' from usage
>>>>
>>>>
>>>> #include <stdio.h>
>>>>
>>>> typedef struct {int x,y;} T;
>>>>
>>>> int main(void) {
>>>> T s;
>>>> s = (T){10,20};
>>>> }
>>>>
>>>
>>> As often seems to be the case, things Fir wants are already available
>>> in C++.
>>>
>>> In C, you need to give a type to "{ 10, 20 }" - as you did here,
>>> making it into a compound literal. The expression "{ 10, 20 }" on
>>> its own cannot be used for assignment to "s" because the type of an
>>> expression must be determined from the expression alone - not from
>>> what you are assigning it to.
>>
>> I think this has been discussed recently but I can't remember the
>> arguments.
>>
>> But people can write:
>>
>> x = 0;
>>
>> and the exact type of '0' can be determined from the type of 'x', so I
>> don't see much difference.
>
> No, 0 is of type "int". As an integer constant expression with value 0,
> it can be /converted/ to any pointer type, giving a null pointer
> constant. It can also be converted to a float, or other arithmetic
> type. But as it stands, "0" has a fixed type - "int".
Same thing. Here there is a tuple of two ints. (The syntax might be
problematical in C outside of initialisation or following a cast.)
Such tuples can be used without having to expose them in the language.
They already occur here: (T){10, 20}.
>>
>> Plus it doesn't see to be a problem here:
>>
>> T s = {10, 20};
>>
>> What determines the type of {10, 20} in this case?
>>
>
> That is initialisation, which is a different matter. Critically, it is
> a declaration and not an expression - it does not produce a value that
> can itself be used.
But it manages to figure out the types. (Even if it is not fussy about
nested {} grouping.)
> (I'd be happy if assignment were a particular kind of statement, rather
> than an expression. I'd be happy if "s = { 10, 20 };" worked in C. It
> doesn't work in C, however - this is one of many reasons why I usually
> work in C++ rather than C.)
OK. Another reason why such things are not a priority in C. You either
use workarounds with macros or switch to a sister language which has
evolved much more dramatically.
>>>
>>> In C++, "s = { 10, 20 };" is valid because "{ 10, 20 }" is treated as
>>> type std::initializer_list<int> (the "int" part is automatically
>>> inferred). Making this work involves quite a bit of additional C++
>>> machinery that does not exist in C.
>> In the language or compiler? Because machinery can be added to C too.
>>
>
> std::initializer_list is a template. Making templates work in C would
> require so many changes that it would be pointless - just use C++.
>
> Maybe the assignment could be made to work in other ways that could be
> more feasible to add to C. It's not something I have thought through in
> detail.
(It seems to work in my language, provided the expression isn't 'open'.
So 'a := (x, y)' will work, as the LHS helps refine the type, but not
'print (x, y)' because the types have not been pinned down.)
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
p = {1,0,0} fir <profesor.fir@gmail.com> - 2026-11-01 14:32 +0100
Re: p = {1,0,0} bartc <bc@freeuk.com> - 2026-11-01 13:41 +0000
Re: p = {1,0,0} fir <profesor.fir@gmail.com> - 2026-11-01 15:10 +0100
Re: p = {1,0,0} fir <profesor.fir@gmail.com> - 2026-11-01 16:13 +0100
Re: p = {1,0,0} fir <profesor.fir@gmail.com> - 2026-11-02 16:46 +0100
Re: p = {1,0,0} David Brown <david.brown@hesbynett.no> - 2026-11-02 17:36 +0100
Re: p = {1,0,0} bartc <bc@freeuk.com> - 2026-11-02 18:47 +0000
Re: p = {1,0,0} fir <profesor.fir@gmail.com> - 2026-11-02 20:54 +0100
Re: p = {1,0,0} fir <profesor.fir@gmail.com> - 2026-11-02 20:56 +0100
Re: p = {1,0,0} David Brown <david.brown@hesbynett.no> - 2026-11-02 21:29 +0100
Re: p = {1,0,0} Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-11-02 21:39 +0100
Re: p = {1,0,0} bartc <bc@freeuk.com> - 2026-11-02 22:58 +0000
Re: p = {1,0,0} David Brown <david.brown@hesbynett.no> - 2026-11-03 11:09 +0100
Re: p = {1,0,0} fir <profesor.fir@gmail.com> - 2026-11-03 13:19 +0100
Re: p = {1,0,0} bartc <bc@freeuk.com> - 2026-11-03 14:07 +0000
Re: p = {1,0,0} fir <profesor.fir@gmail.com> - 2026-11-03 15:45 +0100
Re: p = {1,0,0} fir <profesor.fir@gmail.com> - 2026-11-03 15:54 +0100
Re: p = {1,0,0} fir <profesor.fir@gmail.com> - 2026-11-03 16:48 +0100
Re: p = {1,0,0} fir <profesor.fir@gmail.com> - 2026-11-03 14:29 +0100
Re: p = {1,0,0} fir <profesor.fir@gmail.com> - 2026-11-03 14:42 +0100
Re: p = {1,0,0} fir <profesor.fir@gmail.com> - 2026-11-03 16:09 +0100
Re: p = {1,0,0} fir <profesor.fir@gmail.com> - 2026-11-03 16:18 +0100
Re: p = {1,0,0} fir <profesor.fir@gmail.com> - 2026-11-03 16:38 +0100
Re: p = {1,0,0} fir <profesor.fir@gmail.com> - 2026-11-03 16:55 +0100
Re: p = {1,0,0} fir <profesor.fir@gmail.com> - 2026-11-03 17:06 +0100
Re: p = {1,0,0} bartc <bc@freeuk.com> - 2026-11-03 16:26 +0000
Re: p = {1,0,0} fir <profesor.fir@gmail.com> - 2026-11-03 17:34 +0100
Re: p = {1,0,0} fir <profesor.fir@gmail.com> - 2026-11-03 17:47 +0100
Re: p = {1,0,0} fir <profesor.fir@gmail.com> - 2026-11-03 17:54 +0100
Re: p = {1,0,0} fir <profesor.fir@gmail.com> - 2026-11-03 22:08 +0100
Re: p = {1,0,0} fir <profesor.fir@gmail.com> - 2026-11-04 14:14 +0100
Re: p = {1,0,0} fir <profesor.fir@gmail.com> - 2026-11-04 14:27 +0100
Re: p = {1,0,0} fir <profesor.fir@gmail.com> - 2026-11-05 19:10 +0100
Re: p = {1,0,0} fir <profesor.fir@gmail.com> - 2026-11-05 19:38 +0100
Re: p = {1,0,0} fir <profesor.fir@gmail.com> - 2026-11-07 20:14 +0100
Re: p = {1,0,0} fir <profesor.fir@gmail.com> - 2026-11-07 20:18 +0100
Re: p = {1,0,0} fir <profesor.fir@gmail.com> - 2026-11-07 20:19 +0100
Re: p = {1,0,0} Richard Harnden <richard.nospam@gmail.invalid> - 2026-11-08 09:29 +0000
Re: p = {1,0,0} fir <profesor.fir@gmail.com> - 2026-11-07 20:24 +0100
Re: p = {1,0,0} fir <profesor.fir@gmail.com> - 2026-11-07 20:26 +0100
Re: p = {1,0,0} bartc <bc@freeuk.com> - 2026-11-07 22:18 +0000
Re: p = {1,0,0} fir <profesor.fir@gmail.com> - 2026-11-08 04:17 +0100
Re: p = {1,0,0} fir <profesor.fir@gmail.com> - 2026-11-07 20:50 +0100
Re: p = {1,0,0} bartc <bc@freeuk.com> - 2026-11-07 22:23 +0000
Re: p = {1,0,0} fir <profesor.fir@gmail.com> - 2026-11-08 04:20 +0100
Re: p = {1,0,0} fir <profesor.fir@gmail.com> - 2026-11-08 04:36 +0100
Re: p = {1,0,0} fir <profesor.fir@gmail.com> - 2026-11-08 04:46 +0100
Re: p = {1,0,0} fir <profesor.fir@gmail.com> - 2026-11-08 16:20 +0100
Re: p = {1,0,0} bartc <bc@freeuk.com> - 2026-11-08 17:18 +0000
Re: p = {1,0,0} fir <profesor.fir@gmail.com> - 2026-11-08 19:17 +0100
Re: p = {1,0,0} fir <profesor.fir@gmail.com> - 2026-11-08 19:36 +0100
Re: p = {1,0,0} fir <profesor.fir@gmail.com> - 2026-11-08 19:41 +0100
Re: p = {1,0,0} bartc <bc@freeuk.com> - 2026-11-08 11:19 +0000
Re: p = {1,0,0} fir <profesor.fir@gmail.com> - 2026-11-08 12:44 +0100
Re: p = {1,0,0} fir <profesor.fir@gmail.com> - 2026-11-08 12:56 +0100
Re: p = {1,0,0} fir <profesor.fir@gmail.com> - 2026-11-08 13:12 +0100
Re: p = {1,0,0} fir <profesor.fir@gmail.com> - 2026-11-08 16:12 +0100
Re: p = {1,0,0} fir <profesor.fir@gmail.com> - 2026-11-09 23:47 +0100
Re: p = {1,0,0} fir <profesor.fir@gmail.com> - 2026-11-09 23:56 +0100
Re: p = {1,0,0} bartc <bc@freeuk.com> - 2026-11-10 01:11 +0000
Re: p = {1,0,0} David Brown <david.brown@hesbynett.no> - 2026-11-10 09:24 +0100
Re: p = {1,0,0} bartc <bc@freeuk.com> - 2026-11-10 12:08 +0000
Re: p = {1,0,0} David Brown <david.brown@hesbynett.no> - 2026-11-10 13:50 +0100
Re: p = {1,0,0} bartc <bc@freeuk.com> - 2026-11-10 13:53 +0000
while() and do/while() Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-11-10 11:47 -0800
Re: while() and do/while() bartc <bc@freeuk.com> - 2026-11-10 20:33 +0000
Re: p = {1,0,0} Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-11-10 04:29 -0800
Re: p = {1,0,0} David Brown <david.brown@hesbynett.no> - 2026-11-10 13:57 +0100
Re: p = {1,0,0} Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-11-10 08:57 -0800
Re: p = {1,0,0} fir <profesor.fir@gmail.com> - 2026-11-10 13:51 +0100
Re: p = {1,0,0} fir <profesor.fir@gmail.com> - 2026-11-10 14:08 +0100
Re: p = {1,0,0} fir <profesor.fir@gmail.com> - 2026-11-10 14:17 +0100
Re: p = {1,0,0} fir <profesor.fir@gmail.com> - 2026-11-10 14:22 +0100
Re: p = {1,0,0} bartc <bc@freeuk.com> - 2026-11-10 14:27 +0000
Re: p = {1,0,0} fir <profesor.fir@gmail.com> - 2026-11-10 15:32 +0100
Re: p = {1,0,0} fir <profesor.fir@gmail.com> - 2026-11-10 15:44 +0100
Re: p = {1,0,0} fir <profesor.fir@gmail.com> - 2026-11-10 15:51 +0100
Re: p = {1,0,0} fir <profesor.fir@gmail.com> - 2026-11-10 16:10 +0100
Re: p = {1,0,0} fir <profesor.fir@gmail.com> - 2026-11-10 16:24 +0100
Re: p = {1,0,0} fir <profesor.fir@gmail.com> - 2026-11-10 16:38 +0100
Re: p = {1,0,0} fir <profesor.fir@gmail.com> - 2026-11-10 16:54 +0100
Re: p = {1,0,0} fir <profesor.fir@gmail.com> - 2026-11-10 17:09 +0100
Re: p = {1,0,0} fir <profesor.fir@gmail.com> - 2026-11-10 17:16 +0100
Re: p = {1,0,0} fir <profesor.fir@gmail.com> - 2026-11-10 17:20 +0100
Re: p = {1,0,0} fir <profesor.fir@gmail.com> - 2026-11-10 15:09 +0100
Re: p = {1,0,0} fir <profesor.fir@gmail.com> - 2026-11-10 15:13 +0100
Re: p = {1,0,0} fir <profesor.fir@gmail.com> - 2026-11-10 15:17 +0100
Re: p = {1,0,0} fir <profesor.fir@gmail.com> - 2026-11-10 15:24 +0100
Re: p = {1,0,0} Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-11-02 14:52 -0800
Re: p = {1,0,0} fir <profesor.fir@gmail.com> - 2026-11-03 13:29 +0100
csiph-web