STDC_FIRST_TRAILING_ONE(3)
π STDC_FIRST_TRAILING_ONE(3) π
okay so bestie, welcome to the Library Functions Manual page for stdc_first_trailing_one β yes that's a whole mouthful, and yes it's from the Standard C Library (libc, -lc), and yes we're gonna get through it together π«Ά
β¨ NAME β¨
stdc_first_trailing_one β find the first trailing one in an integer π
like, the one bit that's trailing. not the zeros. keep up bestie π
π¦ SYNOPSIS π¦
Standard C Library (libc, -lc) #include <stdbit.h>
unsigned int
stdc_first_trailing_one_uc(unsigned char value);
unsigned int
stdc_first_trailing_one_us(unsigned short value);
unsigned int
stdc_first_trailing_one_ui(unsigned int value);
unsigned int
stdc_first_trailing_one_ul(unsigned long value);
unsigned int
stdc_first_trailing_one_ull(unsigned long long value);
unsigned int
stdc_first_trailing_one(value);
πΈ DESCRIPTION πΈ
so the stdc_first_trailing_one_type() family of functions returns the index of the least significant set bit in value β and value can be of type unsigned char, unsigned short, unsigned int, unsigned long, or unsigned long long, depending on whether type is uc, us, ui, ul, or ull respectively. slay. five flavours, one vibe π
and the stdc_first_trailing_one(value) type-generic macro? she's the main character fr β she picks the appropriate stdc_first_trailing_one_type() function based on the type of value. no cap, she just knows β¨
now the fun part β the functions stdc_first_trailing_one_ui(), stdc_first_trailing_one_ul(), and stdc_first_trailing_one_ull() are identical to the 4.3BSD functions ffs(3), ffsl(3), and ffsll(3) respectively β EXCEPT they operate on unsigned instead of signed values. that's the whole difference. iconic behaviour honestly π
β RETURN VALUES β
returns the index of the least significant set bit in value. and the bits are numbered like this, bestie: the least significant bit has number 1, and the most significant bit has number w, where w is the number of bits in the type of value. so it's 1-indexed, not 0-indexed β do not come for me, that's just what the page says π
and if no bits are set in value (i.e. value is zero), then one is returned. yeah. zero gives you one. that's not a typo, that's just the rules π
π₯ SEE ALSO π₯
bit_ffs(3)ffs(3)ffsl(3)ffsll(3)stdbit(3)stdc_trailing_zeros(3)stdc_first_trailing_zero(3)stdc_first_leading_one(3)
the whole friend group honestly, go say hi π«Ά
π STANDARDS π
the stdc_first_trailing_one_type() family of functions and the stdc_first_trailing_one() type-generic macro conform to .
nope, that's not me clipping it β the standard's name is literally blank there in the original. mystery standard. ghost standard. she's mysterious πβ¨
π HISTORY π
the stdc_first_trailing_one_type() family of functions and the stdc_first_trailing_one() type-generic macro were added in FreeBSD 15.1. new girl on the block, already thriving π¦
π AUTHOR π
Robert Clausecker <fuz@FreeBSD.org> β thank you for your service, king π«‘π
and that's the whole page babes, go count some bits π§
Debian Β· November 9, 2025 Β· STDC_FIRST_TRAILING_ONE(3) β mwah, see u next time π
π¦ where this page comes from
- freebsd 15.1: base 15.1
- π the page's license: BSD-2-Clause
- Copyright (c) 2025 Robert Clausecker <fuz@FreeBSD.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms