Groups | Search | Server Info | Login | Register
Groups > comp.lang.c.moderated > #499
| Path | csiph.com!eeepc.pasdenom.info!news.pasdenom.info!news.dougwise.org!aioe.org!feeder.news-service.com!newspump.sol.net!posts.news.megabitz.net!nnrp4-asbnva.megabitz.net!not-for-mail |
|---|---|
| From | Hans-Bernhard Bröker <HBBroeker@t-online.de> |
| Newsgroups | comp.lang.c.moderated |
| Subject | Re: Alignment calculation or something like that |
| Date | Fri, 4 Feb 2011 12:46:05 -0600 (CST) |
| Organization | T-Online |
| Sender | clcm@herd.plethora.net |
| Approved | clc@plethora.net |
| Message-ID | <clcm-20110204-0003@plethora.net> (permalink) |
| References | <clcm-20110201-0008@plethora.net> |
| User-Agent | Mozilla/5.0 (Windows; U; Windows NT 6.1; de; rv:1.9.2.11) Gecko/20101013 Thunderbird/3.1.5 |
| Return-Path | <550227619865-0001@t-online.de> |
| X-Original-to | clcm@plethora.net |
| X-Old-complaints-to | usenet-abuse@t-online.de |
| In-Reply-to | <clcm-20110201-0008@plethora.net> |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Mime-Version | 1.0 |
| X-Id | Z46eGwZLoeRPnM40E6yfZAI2mErprz9CqH9mIHpuRJBuYIo6lJqnkz |
| Delivered-To | clcm@localhost.plethora.net |
| X-Old-trace | news.t-online.com 1296682709 00 n26298 VOrgCwnrCQh3NlG 110202 21:38:29 |
| Content-Transfer-encoding | 7bit |
| Lines | 27 |
| NNTP-Posting-Date | 04 Feb 2011 18:46:07 GMT |
| NNTP-Posting-Host | e49fcd18.news.megabitz.net |
| X-Trace | DXC=N;DAG3c_KUak7ngRg7om;c><6FU_Q:4mb^W\Y;gN2lOmWTd@0<dC`1aa7:NWTPgRki7d@DE\31QYeMoRO]O40E3h`H03LY\jMh`AJLgLZi>dOd |
| X-Complaints-To | abuse@megabitz.net |
| Xref | csiph.com comp.lang.c.moderated:499 |
Show key headers only | View raw
On 01.02.2011 23:29, vijk wrote: > /** alignment is a power of 2, it is passed in as a hard coded int **/ > > 1. void*p1,**p2 > > 2. int offset = alignment - 1 + sizeof(void*); > > 3. p2 = (void**)(((size_t)(p1) + offset)& ~(alignment - 1)); > > 4. p2[-1] = p1; > I am trying to understand what/how lines 2 and 3 are doing/calculated. What they're doing is invoke undefined behaviour by assigning an integer that a) isn't known to be stored in a sufficiently wide type, and b) is no longer the address of any given object (even if p1 were, by virtue of code you snipped from the posted snippet) . Given that, the "how" is beside the point. The real question here is why the author of this contraption believed this was something they needed to do --- and then not even deemed it necessary to explain that in the code, where you were supposed to find it, so you wouldn't have had to ask here. -- comp.lang.c.moderated - moderation address: clcm@plethora.net -- you must have an appropriate newsgroups line in your header for your mail to be seen, or the newsgroup name in square brackets in the subject line. Sorry.
Back to comp.lang.c.moderated | Previous | Next | Find similar
Re: Alignment calculation or something like that Hans-Bernhard Bröker <HBBroeker@t-online.de> - 2011-02-04 12:46 -0600
csiph-web