Path: csiph.com!eeepc.pasdenom.info!news.pasdenom.info!news.dougwise.org!gegeweb.org!news.buerger.net!newspump.sol.net!posts.news.megabitz.net!nnrp4-asbnva.megabitz.net!not-for-mail From: Jasen Betts Newsgroups: comp.lang.c.moderated Subject: Re: Alignment calculation or something like that Date: Fri, 4 Feb 2011 12:46:20 -0600 (CST) Organization: Dis (not Dat) Organisation Sender: clcm@herd.plethora.net Approved: clc@plethora.net Message-ID: References: User-Agent: slrn/pre1.0.0-18 (Linux) Return-Path: X-Original-to: clcm@plethora.net X-Old-complaints-to: usenet@wieslauf.sub.de Cancel-Lock: sha1:1VESYRGYcrPPysPQR8ksP/EhW8E= Delivered-To: clcm@localhost.plethora.net X-Notice: Filtered by postfilter v. 0.8.1 X-Face: ?)Aw4rXwN5u0~$nqKj`xPz>xHCwgi^q+^?Ri*+R(&uv2=E1Q0Zk(>h!~o2ID@6{uf8s;a +M[5[U[QT7xFN%^gR"=tuJw%TXXR'Fp~W;(T"1(739R%m0Yyyv*gkGoPA.$b,D.w:z+<'"=-lVT?6 {T?=R^:W5g|E2#EhjKCa+nt":4b}dU7GYB*HBxn&Td$@f%.kl^:7X8rQWd[NTc"P"u6nkisze/Q;8 "9Z{peQF,w)7UjV$c|RO/mQW/NMgWfr5*$-Z%u46"/00mx-,\R'fLPe.)^ Lines: 29 NNTP-Posting-Date: 04 Feb 2011 18:46:22 GMT NNTP-Posting-Host: e49fcd18.news.megabitz.net X-Trace: DXC=N;DAG3c_KUQ[YSEEl4jU`R><6FU_Q:4mR^W\Y;gN2lO]WTd@0 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. when alignment is a power of 2, & ~(alignment - 1) rounds down to the nearest multiple of alignment it's hard to explain, run some numbers through it and see how it behaves. It strikes me as the sort of code that might come from someone who would rather be programming in assembler. -- 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.