STDC_FIRST_TRAILING_ZERO(3)                   FreeBSD Library Functions Manual

NAME

     stdc_first_trailing_zero - find the first trailing zero in an integer

SYNOPSIS

     /* -lc */
     #include <stdbit.h>

     unsigned int
     stdc_first_trailing_zero_uc(unsigned char value);

     unsigned int
     stdc_first_trailing_zero_us(unsigned short value);

     unsigned int
     stdc_first_trailing_zero_ui(unsigned int value);

     unsigned int
     stdc_first_trailing_zero_ul(unsigned long value);

     unsigned int
     stdc_first_trailing_zero_ull(unsigned long long value);

     unsigned int
     stdc_first_trailing_zero(value);

DESCRIPTION

     The stdc_first_trailing_zero_type() family of functions returns the index
     of the least significant clear bit in value, where value is of type
     unsigned char, unsigned short, unsigned int, unsigned long, or unsigned
     long long for type being uc, us, ui, ul, or ull respectively.  The
     stdc_first_trailing_zero(value) type-generic macro picks the appropriate
     stdc_first_trailing_zero_type() function based on the type of value.

RETURN VALUES

     Returns the index of the least significant clear bit in value.  The bits
     are numbered such that 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.  If no bits are clear in value (i.e. value is the bitwise
     complement of zero), zero is returned.

SEE ALSO

     bit_ffc(3), stdbit(3), stdc_trailing_ones(3),
     stdc_first_trailing_ones(3), stdc_first_leading_zero(3)

STANDARDS

     The stdc_first_trailing_zero_type() family of functions and the
     stdc_first_trailing_zero() type-generic macro conform to ISO/IEC
     9899:2024 ("ISO C23").

HISTORY

     The stdc_first_trailing_zero_type() family of functions and the
     stdc_first_trailing_zero() type-generic macro were added in FreeBSD 15.1.

AUTHOR

     Robert Clausecker <fuz@FreeBSD.org>

FreeBSD 15.1-STABLE-HBSD       November 9, 2025    STDC_FIRST_TRAILING_ZERO(3)