STDC_BIT_WIDTH(3)

πŸ“¦ version 15.1, in freebsd 15.1

πŸ’… STDC_BIT_WIDTH(3) πŸ’…

okay so this is STDC_BIT_WIDTH(3), straight out of the Library Functions Manual, and bestie it is so much less scary than the name makes it sound. sit down, grab a boba, we're counting bits 🧚


✨ NAME ✨

stdc_bit_width β€” find the first trailing one in an intege

not me pointing out that the official NAME line literally ends mid-word at "intege" 😭 the page said what it said, i'm just the messenger, fr fr

🌸 SYNOPSIS 🌸

it's Standard C Library (libc, -lc), and first you gotta pull in the header:

#include <stdbit.h>

then all the flavours of the function, each one returning an unsigned int:

unsigned int
stdc_bit_width_uc(unsigned char value);

unsigned int
stdc_bit_width_us(unsigned short value);

unsigned int
stdc_bit_width_ui(unsigned int value);

unsigned int
stdc_bit_width_ul(unsigned long value);

unsigned int
stdc_bit_width_ull(unsigned long long value);

unsigned int
stdc_bit_width(value);

πŸŽ€ DESCRIPTION πŸŽ€

so the stdc_bit_width_type() family of functions returns the number of bits needed to represent value β€” and 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. it's giving "pick your size, we got you" πŸ’…

and then there's the stdc_bit_width(value) type-generic macro, which is the main character of this whole situation: it picks the appropriate stdc_bit_width_type() function based on the type of value. no cap, you don't have to think about it. it just knows. πŸ”₯

also important, bestie: the functions stdc_bit_width_ui(), stdc_bit_width_ul(), and stdc_bit_width_ull() are identical to the 4.3BSD functions fls(3), flsl(3), and flsll(3) respectively β€” except they operate on unsigned instead of signed values. that's the one little difference, and it's iconic of them tbh.


⭐ RETURN VALUES ⭐

it returns the least number of bits needed to represent value.

  • if value is zero, the return value is zero 🫢
  • otherwise it's 1 + ⌊ logβ‚‚ value βŒ‹

that's it. that's the whole vibe check.


🌈 SEE ALSO 🌈

go read the whole friend group, they're all connected iykyk πŸ¦‹


πŸ‘‘ STANDARDS πŸ‘‘

the stdc_bit_width_type() family of functions and the stdc_bit_width() type-generic macro conform to .

and yes, there's literally nothing after "conform to" in the source β€” the standard name got thanos-snapped πŸ™ˆ i'm not about to invent it for you, so take it up with the page, not me

🌸 HISTORY 🌸

the stdc_bit_width_type() family of functions and the stdc_bit_width() type-generic macro were added in FreeBSD 15.1. new-ish, lowkey fresh, we love a recent addition πŸ’œ


πŸ’– AUTHOR πŸ’–

Robert Clausecker <fuz@FreeBSD.org> β€” thank you for your service, king 🫑


aaand that's the page!! mwah πŸ’‹ this was STDC_BIT_WIDTH(3) from Debian, dated November 9, 2025 β€” shouted out at the very bottom like a true sign-off. go forth and count your bits, bestie, you're gonna slay βœ¨πŸŽ€πŸ’…

πŸ“¦ where this page comes from
  • freebsd 15.1: base 15.1
  • πŸ“œ the page's license: BSD-2-Clause
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms