Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #150811
| Path | csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Keith Thompson <Keith.S.Thompson+u@gmail.com> |
| Newsgroups | comp.lang.c |
| Subject | Re: allocating two objects in one malloc |
| Date | Tue, 24 Mar 2020 13:10:03 -0700 |
| Organization | None to speak of |
| Lines | 40 |
| Message-ID | <87ftdxpl9g.fsf@nosuchdomain.example.com> (permalink) |
| References | <20301314-7f32-4cab-924d-c55c7a5175d6@googlegroups.com> <r4tl42$ch6$1@news.albasani.net> <d640b96b-9998-4c5b-944d-bfd372fcde93@googlegroups.com> <e05akg-7kp1.ln1@mail.home.palmen-it.de> <31d5ac0f-889d-4918-9313-a6e1b97eebd2@googlegroups.com> <op6akg-jfb2.ln1@mail.home.palmen-it.de> <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> <r5d9bt$4ak$1@dont-email.me> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8 |
| Content-Transfer-Encoding | 8bit |
| Injection-Info | reader02.eternal-september.org; posting-host="cddcfdf96fa244ceeb789ef1142863d8"; logging-data="5889"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/2iVKdNSb/2wVeeiD7HbZu" |
| User-Agent | Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) |
| Cancel-Lock | sha1:Ggy2bBnVfNtgQG7iQwbFlc+exfU= sha1:TcJHNoLYM5qRFHslKEXz8PaQQ1U= |
| Xref | csiph.com comp.lang.c:150811 |
Show key headers only | View raw
Lew Pitcher <lew.pitcher@digitalfreehold.ca> writes:
> On March 24, 2020 11:11, 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.
> [snip]
>
> To me, this seems to be a re-implementation of a pattern seen in 40-year-old
> programs written to the K&R standard.
Yes, that's exactly what it is.
The old pattern is called the "struct hack". It worked as expected with
more or all compilers, but strictly speaking it had (and still has)
undefined behavior. Quoting the C99 Rationale:
The Committee felt that, although there was no way to
implement the “struct hack” in C89, it was nonetheless a
useful facility. Therefore the new feature of “flexible array
members” was introduced. Apart from the empty brackets, and the
removal of the “-1” in the malloc call, this is used in the
same way as the struct hack, but is now explicitly valid code.
See also question 2.6 of the comp.lang.c FAQ <http://www.c-faq.com/>.
--
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