GETC(3POSIX)

πŸ’– GETC(3POSIX) πŸ’–

okay bestie, welcome to the POSIX Programmer's Manual, GETC(3POSIX) edition ✨


🚨 PROLOG 🚨

Real talk first, no cap: this manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (so like, go check the corresponding Linux manual page for the deets on Linux behavior), or honestly the interface may not even be implemented on Linux at all. πŸ’€


✨ NAME ✨

getc β€” get a byte from a stream πŸ“


🌸 SYNOPSIS 🌸

#include <stdio.h>

int getc(FILE *stream);

πŸ’… DESCRIPTION πŸ’…

The functionality described on this reference page is aligned with the ISO C standard. And if there's any conflict between the requirements described here and the ISO C standard? That's unintentional, bestie, it was not the vibe. This volume of POSIX.1‐2017 defers to the ISO C standard. Periodt. πŸ‘‘

The getc() function shall be equivalent to fgetc(), with one lil caveat: if it's implemented as a macro it may evaluate stream more than once 😭. So the argument should never be an expression with side-effects. Like, ever. πŸ™ˆ


🫢 RETURN VALUE 🫢

Refer to fgetc(). That's it, that's the whole section. Go look it up, iykyk. πŸ’œ


πŸŽ€ ERRORS πŸŽ€

Refer to fgetc().

The following sections are informative. (yes queen, they said it, not me)


🌈 EXAMPLES 🌈

None. 😭 iconic of them honestly


πŸ’œ APPLICATION USAGE πŸ’œ

Okay so this part is highkey important, listen up. If the integer value returned by getc() is stored into a variable of type char and then compared against the integer constant EOF, the comparison may never succeed β€” because sign-extension of a variable of type char on widening to integer is implementation-defined. So that check? It might just... never hit. Not the vibe at all. πŸ’€

And since it may be implemented as a macro, getc() may treat incorrectly a stream argument with side-effects. In particular, getc(*f++) does not necessarily work as expected. So if you're in that situation, use of this function should be preceded by "#undefgetc" β€” yes, exactly like that, no space β€” and also fgetc() could be used instead. Slay, we love a backup plan. 🧚


⭐ RATIONALE ⭐

None. πŸ’…


πŸ¦‹ FUTURE DIRECTIONS πŸ¦‹

None. 🌸


πŸ‘‘ SEE ALSO πŸ‘‘

  • Section 2.5, Standard I/O Streams, fgetc()
  • The Base Definitions volume of POSIX.1‐2017, <stdio.h>

Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .

Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .


and that's the whole page bestie!! brought to you by IEEE/The Open Group, 2017, on GETC(3POSIX) β€” mwah, go read fgetc() next, love u 🫢✨