Groups | Search | Server Info | Login | Register


Groups > comp.lang.c.moderated > #499

Re: Alignment calculation or something like that

From Hans-Bernhard Bröker <HBBroeker@t-online.de>
Newsgroups comp.lang.c.moderated
Subject Re: Alignment calculation or something like that
Date 2011-02-04 12:46 -0600
Organization T-Online
Message-ID <clcm-20110204-0003@plethora.net> (permalink)
References <clcm-20110201-0008@plethora.net>

Show all headers | 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


Thread

Re: Alignment calculation or something like that Hans-Bernhard Bröker <HBBroeker@t-online.de> - 2011-02-04 12:46 -0600

csiph-web