From owner-freebsd-current@FreeBSD.ORG Thu Feb 8 23:08:57 2007 Return-Path: X-Original-To: current@freebsd.org Delivered-To: freebsd-current@FreeBSD.ORG Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 5910716A402 for ; Thu, 8 Feb 2007 23:08:57 +0000 (UTC) (envelope-from schweikh@schweikhardt.net) Received: from rs1.shuttle.de (rs1.shuttle.de [194.95.249.3]) by mx1.freebsd.org (Postfix) with ESMTP id 1D5CC13C474 for ; Thu, 8 Feb 2007 23:08:57 +0000 (UTC) (envelope-from schweikh@schweikhardt.net) Received: by rs1.shuttle.de (Postfix, from userid 10) id 564DC2183D; Thu, 8 Feb 2007 23:40:57 +0100 (CET) Received: from hal9000.schweikhardt.net (localhost [127.0.0.1]) by hal9000.schweikhardt.net (8.13.8/8.13.8) with ESMTP id l18MOiXj003326; Thu, 8 Feb 2007 23:24:44 +0100 (CET) (envelope-from schweikh@hal9000.schweikhardt.net) Received: (from schweikh@localhost) by hal9000.schweikhardt.net (8.13.8/8.13.8/Submit) id l18MOi59003325; Thu, 8 Feb 2007 23:24:44 +0100 (CET) (envelope-from schweikh) Date: Thu, 8 Feb 2007 23:24:44 +0100 From: Jens Schweikhardt To: Luigi Rizzo Message-ID: <20070208222444.GA2994@schweikhardt.net> References: <20070207004131.A62183@xorpc.icir.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20070207004131.A62183@xorpc.icir.org> User-Agent: Mutt/1.5.13 (2006-08-11) Cc: current@freebsd.org Subject: Re: C macro to find the next power of 2 ? X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 08 Feb 2007 23:08:57 -0000 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)