Skip to content

Instantly share code, notes, and snippets.

View mahdavipanah's full-sized avatar
💻
Wired in

Hamid Mahdavi mahdavipanah

💻
Wired in
View GitHub Profile
@brettlangdon
brettlangdon / Wallpapers.md
Last active December 16, 2024 19:47
Wallpapers

Wallpapers

Install with git git clone https://gist.github.com/85942af486eb79118467.git ~/Pictures/wallpapers

@jfriedly
jfriedly / c-putc-vs-fputc.rst
Last active March 2, 2023 07:21
The difference between ``putc`` and ``fputc`` in C: notes from a conversation with Shevek

C: putc vs fputc

From the putc man page, "putc() is equivalent to fputc() except that it may be implemented as a macro which evaluates stream more than once." I wasn't sure what this meant so I asked Shevek. He launched into a lambda calculus explanation that eventually boiled down to: putc may evaluate it's arguments more than once, but fputc evaluates them exactly once. This is because putc is implemented as a macro and the C preprocessor just does string substitution, leading to examples like the ones below.

Ignoring what putc and fputc actually do, let's look at a simplified version where they both simply do one operation twice and another operation once: