Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 8 Feb 2007 23:24:44 +0100
From:      Jens Schweikhardt <schweikh@schweikhardt.net>
To:        Luigi Rizzo <rizzo@icir.org>
Cc:        current@freebsd.org
Subject:   Re: C macro to find the next power of 2 ?
Message-ID:  <20070208222444.GA2994@schweikhardt.net>
In-Reply-To: <20070207004131.A62183@xorpc.icir.org>
References:  <20070207004131.A62183@xorpc.icir.org>

next in thread | previous in thread | raw e-mail | index | archive | help
Luigi,

...
# 
# But i was wondering if there is some simpler code which
# can still be computed as a compile-time constant?

Is this requirement non-negotiable? Maybe in the days of C99
and run-time sized arrays it's worth thinking about other solutions
than CPP magic.

For this and other bit twiddling hacks in C (mostly functional), see
http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2

Regards,

	Jens
-- 
Jens Schweikhardt http://www.schweikhardt.net/
SIGSIG -- signature too long (core dumped)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20070208222444.GA2994>