Path: csiph.com!newsfeed.xs4all.nl!newsfeed9.news.xs4all.nl!feeder1.feed.usenet.farm!feed.usenet.farm!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: on why declare a struct with a single array in it Date: Sat, 20 Nov 2021 15:52:32 -0800 Organization: None to speak of Lines: 29 Message-ID: <875ysmjsfz.fsf@nosuchdomain.example.com> References: <86tughjjm7.fsf@levado.to> <87pmr5qih6.fsf@bsb.me.uk> <87czmwosiq.fsf@nosuchdomain.example.com> <874k87q35r.fsf@nosuchdomain.example.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: reader02.eternal-september.org; posting-host="a1aa0dcd5f82470090faf86702e2798a"; logging-data="27669"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+ZshqFW/nJETRCNPhJ9VFx" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) Cancel-Lock: sha1:gaCqA5tUXFM98TsMfUUx+shwrd8= sha1:hfhfTKYRIMqLX62NCm4VNMaxme0= Xref: csiph.com comp.lang.c:163533 David Brown writes: > On 19/11/2021 21:52, Keith Thompson wrote: [...] >> Perhaps -- but typically that information is not stored in the pointer >> itself. If it were, all void* values would have to store that extra >> information. >> >> (I think it's easier to store bookkeeping data before the allocated >> space. If you store it after the space, it's hard to know where it is.) > > That's the most common way for a simple malloc/free system. > > It has always struck me as a mistake that C did things that way - in my > opinion, "free" should have taken an additional parameter of the size > for the deallocation. Meh. That would have introduced another rich source of programming errors (passing the wrong size). Probably most implementations would have kept track of the size anyway, so they could detect errors. As long as they're keeping track, why make the user do so as well? Perhaps a lower-level allocator might be more efficient if user code is required to keep track, but I don't think it would be all that useful for most applications. -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com Working, but not speaking, for Philips void Void(void) { Void(); } /* The recursive call of the void */