GETC(3P)

πŸ’– GETC(3P) β€” get a byte from a stream πŸ’–

okay bestie, pull up a chair, we're doing the POSIX Programmer's Manual today β€” specifically the page for getc, from the POSIX Programmer's Manual. ✨


🌸 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 if that's your situation, go consult the corresponding Linux manual page for the details of Linux behavior. Or, plot twist, the interface may not be implemented on Linux at all. πŸ™ˆ So like… check before you commit, okay?


πŸ‘‘ NAME πŸ‘‘

getc β€” grab a byte from a stream. that's it. that's the whole job. πŸ’…


✨ SYNOPSIS ✨

#include <stdio.h>

int getc(FILE *stream);

she's small, she's tidy, she returns an int πŸŽ€


πŸ¦‹ DESCRIPTION πŸ¦‹

So the vibe here: the functionality described on this reference page is aligned with the ISO C standard. Any conflict between the requirements described here and the ISO C standard is unintentional. This volume of POSIX.1‐2017 defers to the ISO C standard. 🫢

And now the actual tea β˜• β€” the getc() function shall be equivalent to fgetc(), except that if it's implemented as a macro, it may evaluate stream more than once. Which means the argument should never be an expression with side-effects. 🚨 fr fr, do not do that.


πŸ’€ RETURN VALUE πŸ’€

Not her turn to explain: Refer to fgetc(). 🫑


🌈 ERRORS 🌈

Refer to fgetc(). Same energy, same page, go read hers.

And also, heads up: the following sections are informative. (i.e. the vibes sections, not the rules sections ✨)


πŸ“ EXAMPLES πŸ“

None. 😭 not a single one. iconic of her honestly.


πŸ’œ APPLICATION USAGE πŸ’œ

okay so this is the part where I hold your hand, bestie:

  • 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 like. store it in an int. please.
  • 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. Therefore, use of this function should be preceded by #undefgetc in such situations; fgetc() could also be used. 🧚

Two escape hatches, pick your fave: #undefgetc or just call fgetc(). 🫢


πŸŽ€ RATIONALE πŸŽ€

None. she said no thoughts, head empty. respect. πŸ’…


⭐ FUTURE DIRECTIONS ⭐

None. no drama on the horizon. we love a stable queen. πŸ‘‘


πŸ”₯ SEE ALSO πŸ”₯

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

iykyk β€” go read fgetc(), she's the main character, getc is literally her macro-flavored twin. 🌸


okay legal moment, stay with me, this matters:

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!! πŸ’–βœ¨πŸŽ€πŸ¦‹πŸŒΈ

this edition dropped in 2017, courtesy of IEEE/The Open Group, and it's the GETC(3P) page β€” go forth and read your bytes responsibly, mwah πŸ’…

πŸ“¦ where this page comes from