Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #150810
| From | Keith Thompson <Keith.S.Thompson+u@gmail.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: allocating two objects in one malloc |
| Date | 2020-03-24 13:05 -0700 |
| Organization | None to speak of |
| Message-ID | <87k139plh4.fsf@nosuchdomain.example.com> (permalink) |
| References | (6 earlier) <8c84cb75-e3a4-4820-80e3-b471d9f7e1a2@googlegroups.com> <buiakg-egj2.ln1@mail.home.palmen-it.de> <67e8bd22-fea3-43ad-9484-0cfba94c3352@googlegroups.com> <0600b6ae-a692-47d8-8e15-c0eb5286a8da@googlegroups.com> <bd5529e8-ff39-412a-8b73-17d8456a2052@googlegroups.com> |
Thiago Adams <thiago.adams@gmail.com> writes:
> On Tuesday, March 24, 2020 at 12:12:10 PM UTC-3, James Kuyper wrote:
>> On Wednesday, March 18, 2020 at 7:48:47 PM UTC-4, Thiago Adams wrote:
>> ...
>> > Something I have considered to suggest for the C language
>> > is make the operator [] available for empty arrays at the end.
>> >
>> >
>> > struct array
>> > {
>> > int size;
>> > int capacity;
>> > char data[];
>> > };
>>
>> You're 21 years late - flexible array members were added in C99.
>
> My suggestion is not add flexible arrays.
> It is make the operator [ ] works as synonymous
>
> sample (Array has the flexible array member called data)
>
> struct Array a;
> a[0] = 1;
>
> same as or synonymous of :
>
> a.data[0] = 1;
>
> my suggestion is make this a[0] syntax synonymous of
> a.data[0] where data or other name is the flexible array
> member.
>
> This is useful in case we want to put some information
> together with arrays and still use array notation.
That sounds like enabling operator overloading, but only for this one
specific case. IMHO it's not sufficiently useful.
You can, if you like, do something like this:
struct Array a;
#define a_a a.data
a_a[0] = 1;
(Please pretend that I picked more meaningful names.)
--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips Healthcare
void Void(void) { Void(); } /* The recursive call of the void */
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
allocating two objects in one malloc Thiago Adams <thiago.adams@gmail.com> - 2020-03-18 10:14 -0700
Re: allocating two objects in one malloc Bonita Montero <Bonita.Montero@gmail.com> - 2020-03-18 18:17 +0100
Re: allocating two objects in one malloc Thiago Adams <thiago.adams@gmail.com> - 2020-03-18 10:55 -0700
Re: allocating two objects in one malloc Thiago Adams <thiago.adams@gmail.com> - 2020-03-18 11:01 -0700
Re: allocating two objects in one malloc felix@palmen-it.de (Felix Palmen) - 2020-03-18 19:14 +0100
Re: allocating two objects in one malloc Thiago Adams <thiago.adams@gmail.com> - 2020-03-18 11:35 -0700
Re: allocating two objects in one malloc felix@palmen-it.de (Felix Palmen) - 2020-03-18 19:44 +0100
Re: allocating two objects in one malloc Thiago Adams <thiago.adams@gmail.com> - 2020-03-18 12:07 -0700
Re: allocating two objects in one malloc Bart <bc@freeuk.com> - 2020-03-18 20:39 +0000
Re: allocating two objects in one malloc Thiago Adams <thiago.adams@gmail.com> - 2020-03-18 13:52 -0700
Re: allocating two objects in one malloc felix@palmen-it.de (Felix Palmen) - 2020-03-18 23:11 +0100
Re: allocating two objects in one malloc Thiago Adams <thiago.adams@gmail.com> - 2020-03-18 16:48 -0700
Re: allocating two objects in one malloc Bart <bc@freeuk.com> - 2020-03-19 01:16 +0000
Re: allocating two objects in one malloc Thiago Adams <thiago.adams@gmail.com> - 2020-03-24 06:11 -0700
Re: allocating two objects in one malloc Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-03-24 14:49 +0000
Re: allocating two objects in one malloc Thiago Adams <thiago.adams@gmail.com> - 2020-03-24 08:46 -0700
Re: allocating two objects in one malloc James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-03-24 07:50 -0700
Re: allocating two objects in one malloc Thiago Adams <thiago.adams@gmail.com> - 2020-03-24 08:48 -0700
Re: allocating two objects in one malloc chad <cdalten@gmail.com> - 2020-03-19 05:15 -0700
Re: allocating two objects in one malloc James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-03-24 08:11 -0700
Re: allocating two objects in one malloc Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2020-03-24 11:35 -0400
Re: allocating two objects in one malloc Richard Damon <Richard@Damon-Family.org> - 2020-03-24 13:50 -0400
Re: allocating two objects in one malloc Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-03-24 20:58 +0000
Re: allocating two objects in one malloc Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-03-24 13:10 -0700
Re: allocating two objects in one malloc Thiago Adams <thiago.adams@gmail.com> - 2020-03-24 08:52 -0700
Re: allocating two objects in one malloc Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-03-24 13:05 -0700
Re: allocating two objects in one malloc Bonita Montero <Bonita.Montero@gmail.com> - 2020-03-18 19:53 +0100
Re: allocating two objects in one malloc Bart <bc@freeuk.com> - 2020-03-18 20:29 +0000
Re: allocating two objects in one malloc jadill33@gmail.com - 2020-03-18 13:44 -0700
Re: allocating two objects in one malloc Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-03-18 21:00 +0000
Re: allocating two objects in one malloc Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2020-03-18 10:18 -0700
Re: allocating two objects in one malloc felix@palmen-it.de (Felix Palmen) - 2020-03-18 18:43 +0100
Re: allocating two objects in one malloc Bonita Montero <Bonita.Montero@gmail.com> - 2020-03-18 18:55 +0100
Re: allocating two objects in one malloc Thiago Adams <thiago.adams@gmail.com> - 2020-03-18 10:56 -0700
Re: allocating two objects in one malloc Bonita Montero <Bonita.Montero@gmail.com> - 2020-03-18 19:06 +0100
Re: allocating two objects in one malloc felix@palmen-it.de (Felix Palmen) - 2020-03-18 19:01 +0100
Re: allocating two objects in one malloc James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-03-18 14:21 -0400
Re: allocating two objects in one malloc felix@palmen-it.de (Felix Palmen) - 2020-03-18 19:30 +0100
Re: allocating two objects in one malloc James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-03-18 15:08 -0400
csiph-web