Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Anton Shepelev Newsgroups: comp.lang.c Subject: Re: Pointer conversion and alignment Date: Sun, 18 Nov 2018 15:31:58 +0300 Organization: A noiseless patient Spider Lines: 41 Message-ID: <20181118153158.b864bfe884c19fbdedfa8ade@gmail.com> References: <20181117143819.43938ee34006bbcc1826bf0c@gmail.com> <20181117173706.aa796408d8f064693c860302@gmail.com> <87r2fjl8pl.fsf@bsb.me.uk> <20181118004332.f3bbecb2e75db48245ac0cf9@gmail.com> <87efbjku7v.fsf@bsb.me.uk> <20181118132355.24c369bc7585b7c167c097ed@gmail.com> <8736rylj4u.fsf@bsb.me.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Injection-Info: reader01.eternal-september.org; posting-host="f7d42647b661201d8d2bb61c958ddd88"; logging-data="17743"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/8aGQTDIwxPBrt49z/gQLVQ2i03JP2EIM=" Cancel-Lock: sha1:s2AHcHG0/ATpZgEeGM7FJscy3Oc= X-Newsreader: Sylpheed 3.7.0 (GTK+ 2.24.30; i686-pc-mingw32) Xref: csiph.com comp.lang.c:138104 Ben Bacarisse: > If da_addemp returned the pointer one could write > > memcpy(da_addemp(&a), &v, sizeof v); > > I'm not seeing the value of getting the pointer via > another object. Maybe it's because you want to provide > the index (the current return value) as well? Yes. Also, in production code one shall check for error before invoking memcpy(). > I'm the sort of programmer who'd be tempted to write > > a[da_addamp(&a, ...)] = 42; > > which is not safe! Well are you bold! I try not to mix expressions with side effects. > > But the compiler -- why did it not optimise away my > > accesses to int* objects through char** pointers even > > with -O5? > > Sorry, I'm not sure what that's about. Did you post an > example? If so, I must have missed it. (Did you mean > -Ofast rather than -O5?) -O5 in GCC. I didn't know it accepted any non-negative integer with the -O option. I have changed it to -O3 now. My code: dynarray.h: https://pastebin.com/raw/VYFG3gBS dynarray.c: https://pastebin.com/raw/DQCEWgrH da_test.c : https://pastebin.com/raw/vMmq8NKJ -- () ascii ribbon campaign -- against html e-mail /\ http://preview.tinyurl.com/qcy6mjc [archived]