.\" Copyright (c) 1989, 1991, 1993 .\" The Regents of the University of California. All rights reserved. .\" .\" This code is derived from software contributed to Berkeley by .\" Paul Vixie. .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. All advertising materials mentioning features or use of this software .\" must display the following acknowledgement: .\" This product includes software developed by the University of .\" California, Berkeley and its contributors. .\" 4. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" @(#)bitstring.3 8.1 (Berkeley) 7/19/93 .\" %FreeBSD: src/share/man/man3/bitstring.3,v 1.6.2.5 2001/12/17 11:30:11 ru Exp % .\" .\" $FreeBSD$ .\" .Dd July 19, 1993 .Dt BITSTRING 3 .Os .Sh 名称 .Nm bit_alloc , .Nm bit_clear , .Nm bit_decl , .Nm bit_ffs , .Nm bit_nclear , .Nm bit_nset , .Nm bit_set , .Nm bitstr_size , .Nm bit_test .Nd ビット列操作マクロ .Sh 書式 .In bitstring.h .Ft bitstr_t * .Fn bit_alloc "int nbits" .Ft void .Fn bit_decl "bitstr_t *name" "int nbits" .Ft void .Fn bit_clear "bitstr_t *name" "int bit" .Ft void .Fn bit_ffc "bitstr_t *name" "int nbits" "int *value" .Ft void .Fn bit_ffs "bitstr_t *name" "int nbits" "int *value" .Ft void .Fn bit_nclear "bitstr_t *name" "int start" "int stop" .Ft void .Fn bit_nset "bitstr_t *name" "int start" "int stop" .Ft void .Fn bit_set "bitstr_t *name" "int bit" .Ft int .Fn bitstr_size "int nbits" .Ft int .Fn bit_test "bitstr_t *name" "int bit" .Sh 解説 これらのマクロはビット列を操作します。 .Pp マクロ .Fn bit_alloc は、 .Fa nbits 個のビットを格納するのに十分な空間を指す型 .Dq Fa "bitstr_t *" のポインタを返します。または、空間が利用できない場合は .Dv NULL を返します。 .Pp マクロ .Fn bit_decl は、 .Fa nbits 個のビットを格納するのに十分な空間をスタックに割り付けます。 .Pp マクロ .Fn bitstr_size は、 .Fa nbits 個のビットを格納するのに必要な、型 .Fa bitstr_t の要素の数を返します。これはビット列をコピーするのに便利です。 .Pp マクロ .Fn bit_clear とマクロ .Fn bit_set は、ビット列 .Ar name の中の、0 を起点として .Fa bit 番目のビットをクリアまたは設定します。 .Pp マクロ .Fn bit_nset とマクロ .Fn bit_nclear は、ビット列 .Ar name の中の .Fa start から .Fa stop までの (0 を起点として番号付けした) ビットをセットまたは クリアします。 .Pp マクロ .Fn bit_test は、ビット列 .Ar name 内で、0 を起点として .Fa bit 番目のビットがセットされている場合、評価結果は 0 でない値になり、 それ以外の場合は 0 と評価されます。 .Pp マクロ .Fn bit_ffs は、 .Ar name が参照する .Fa nbits ビットの配列のなかで、セットされたビットが最初に現れる位置を 0 を起点として番号付けした値を、 .Fa value が参照する位置に格納します。どのビットも設定されていない場合、 .Fa value が参照する位置に、\-1 が設定されます。 .Pp マクロ .Fn bit_ffc は、 .Ar name が参照する .Fa nbits ビットの配列のなかで、セットされていないビットが最初に現れる位置を、 0 を起点として番号付けした値を、 .Fa value が参照する位置に格納します。どのビットも設定されている場合、 .Fa value が参照する位置に、\-1 が設定されます。 .Pp これらのマクロの引数は、 1 回だけ評価され、安全な副作用がある 可能性があります。 .Sh 例 .Bd -literal -offset indent #include #include \&... #define LPR_BUSY_BIT 0 #define LPR_FORMAT_BIT 1 #define LPR_DOWNLOAD_BIT 2 \&... #define LPR_AVAILABLE_BIT 9 #define LPR_MAX_BITS 10 make_lpr_available() { bitstr_t bit_decl(bitlist, LPR_MAX_BITS); ... bit_nclear(bitlist, 0, LPR_MAX_BITS - 1); ... if (!bit_test(bitlist, LPR_BUSY_BIT)) { bit_clear(bitlist, LPR_FORMAT_BIT); bit_clear(bitlist, LPR_DOWNLOAD_BIT); bit_set(bitlist, LPR_AVAILABLE_BIT); } } .Ed .Sh 関連項目 .Xr malloc 3 .Sh 歴史 .Nm bitstring 関数は .Bx 4.4 ではじめて登場しました。 .\" kuma