ffs(3)

๐Ÿ’– ffs(3) โ€” find first bit set in a word ๐Ÿ’–

okay bestie, buckle up, because today we're getting down to the bits ๐Ÿฆ‹ this is the ffs(3) page from your friendly neighborhood Library Functions Manual, and it's genuinely so cute and so useful. no cap.

๐ŸŒธ LIBRARY ๐ŸŒธ

Standard C library (libc, -lc) โ€” the iconic one, the one your linker already knows and loves ๐Ÿ’…


โœจ SYNOPSIS โœจ

#include <strings.h>

int ffs(int i);
int ffsl(long i);
int ffsll(long long i);

literally three functions, three vibes, one job ๐Ÿ”ฅ

๐ŸŽ€ Feature Test Macro Requirements for glibc (see feature_test_macros(7)) ๐ŸŽ€

not me having to gate-keep which macros you define before glibc will even let you play ๐Ÿ˜ญ here's the whole situation:

  • ffs():
    • Since glibc 2.12:
_XOPEN_SOURCE >= 700
    || ! (_POSIX_C_SOURCE >= 200809L)
    || /* glibc >= 2.19: */ _DEFAULT_SOURCE
    || /* glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
  • Before glibc 2.12: none โ€” no macros needed, it was just free real estate ๐Ÿซถ
  • ffsl(), ffsll():
    • Since glibc 2.27: _DEFAULT_SOURCE
    • Before glibc 2.27: _GNU_SOURCE

๐ŸŒˆ DESCRIPTION ๐ŸŒˆ

so here's the tea โ˜• the ffs() function returns the position of the first (least significant) bit set in the word i. the least significant bit is position 1, and the most significant position is, for example, 32 or 64. we count from one bestie, not from zero, that's just the house rules ๐Ÿ’…

the functions ffsll() and ffsl() do the exact same thing but take arguments of possibly different size. same energy, bigger (or smaller) word ๐ŸŒธ


๐Ÿ‘‘ RETURN VALUE ๐Ÿ‘‘

these functions return the position of the first bit set, or 0 if no bits are set in i. that's it. zero means "nothing to see here", periodt ๐ŸŽ€


๐Ÿ’… ATTRIBUTES ๐Ÿ’…

for an explanation of the terms used in this section, see attributes(7). (lore drop โœจ)

  • Interface: ffs(), ffsl(), ffsll()
  • Attribute: Thread safety
  • Value: MT-Safe

translation: she's MT-Safe and she knows it ๐Ÿ”ฅ no locking drama, just vibes.


โญ STANDARDS โญ

  • ffs() โ€” POSIX.1-2001, POSIX.1-2008, 4.3BSD.
  • ffsl()
  • ffsll() โ€” GNU.

(the last two are GNU's contribution to the group chat, iykyk ๐Ÿ’œ)


๐Ÿซถ SEE ALSO ๐Ÿซถ


๐Ÿ’€ friendly reminder bestie: this page is ffs(3), the find first bit set one. if you wanted "for f***'s sake" that's not a syscall, that's just your Monday.

okay that's the whole page, mwah ๐Ÿ’– this was Linux man-pages 6.20, dated 2026-02-08, and she ate, no crumbs ๐Ÿ‘‘ bye bestie, go count some bits ๐ŸŒŸ

๐Ÿ“ฆ where this page comes from
  • arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
  • nixpkgs unstable: man-pages 6.20
  • ๐Ÿ“œ the page's license: Linux-man-pages-copyleft
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms