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
- Since glibc 2.27:
๐ 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
- Copyright 1993, David Metcalfe <david@prism.demon.co.uk>
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms