Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Generic read/write function - casting vs union Date: Thu, 22 Sep 2016 11:48:51 -0700 Organization: None to speak of Lines: 26 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="945944de09706c9b4e29b53c9d2efdc2"; logging-data="1074"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1++wLNYH/w9CfcnqlciYoCY" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:R4DJlOQJVrjMDDWSveHY0FSMNsU= sha1:JnjeDvGphcAnUh282uxHcy6Albw= Xref: csiph.com comp.lang.c:93910 Richard Heathfield writes: > On 22/09/16 10:33, Noob wrote: [...] >> Something I didn't mention is that the access function actually >> updates buf in the EPILOG. >> >> buf->in += len; >> >> Is it *100%* guaranteed that incrementing buf->in is strictly >> equivalent to incrementing buf->out ? > > You can't do pointer arithmetic on void *. :-) > > But you can assign to an unsigned char *, and increment that instead. Note that gcc permits pointer arithmetic on void* as an extension. I don't recommend using that extension, but be aware that gcc will not warn about such pointer arithmetic by default. You can use -pedantic or -pedantic-errors to disable the warning and get the required diagnostics. -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"