wcwidth(3)

โœจ wcwidth(3) โ€” the manual page bestie ๐Ÿ’…

okay so this is a page from the Library Functions Manual (yes, the libc girlies) and honestly? it's a tiny function with main character energy. let's get into it ๐ŸŽ€


๐Ÿฆ‹ NAME

wcwidth โ€” figure out how many columns a wide character takes up, bestie. that's it. that's the whole job.


๐Ÿ“š LIBRARY

Standard C library (libc, -lc) โ€” she's a classic, no cap.


๐ŸŒธ SYNOPSIS

#define _XOPEN_SOURCE       /* See feature_test_macros(7) */
#include <wchar.h>

int wcwidth(wchar_t wc);

like, you gotta define _XOPEN_SOURCE first (peep feature_test_macros(7) for the lore ๐Ÿ’–) and then pull in <wchar.h>.


๐Ÿ’– DESCRIPTION

so wcwidth() literally returns the number of columns you need to represent the wide character wc. that's the vibe.

  • if wc is a printable wide character, the value is at least 0 โœจ
  • if wc is the null wide character (L'\0'), the value is 0 ๐Ÿซถ
  • otherwise? -1 gets returned, and honestly, same ๐Ÿ™ˆ

๐Ÿ‘‘ RETURN VALUE

wcwidth() hands you back the number of column positions for wc. periodt. ๐Ÿ’…


๐ŸŒˆ ATTRIBUTES

for what all these words even mean, go look at attributes(7) โ€” iykyk.

here's the tea on wcwidth():

  • Interface: wcwidth()
  • Attribute: Thread safety
  • Value: MT-Safe locale

โญ STANDARDS

POSIX.1-2008. iconic. certified. ๐Ÿ’ฏ


๐Ÿงš HISTORY

POSIX.1-2001 โ€” she's been around a minute.

and a lil throwback for you: before glibc 2.2.5, glibc was out here using this prototype instead:

int wcwidth(wint_t wc);

not me with the wint_t instead of wchar_t ๐Ÿ˜ญ ancient times fr fr.


๐Ÿ”ฅ NOTES

the behavior of wcwidth() depends on the LC_CTYPE category of the current locale. so like... your locale is the one calling the shots here, not you. lowkey humbling. ๐ŸŒธ


๐Ÿซถ SEE ALSO


vibe check: this is Linux man-pages 6.20, dated 2026-02-08, for wcwidth(3). slay, stay hydrated, and always define _XOPEN_SOURCE before you include anything ๐Ÿ’œโœจ
๐Ÿ“ฆ 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: GPL-2.0-or-later
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms