TYPEOF(3)

πŸ“¦ version 11.0, in nixpkgs unstable

✨ TYPEOF(3) ✨

Okay so bestie, this is the TYPEOF(3) page from the Library Functions Manual πŸ’– and it's literally all about the typeof GNU extension. Let me break it down for you, no cap, because this thing is actually so useful and lowkey iconic. 🫢


🌸 NAME 🌸

typeof β€” GNU extension for type of an expression


πŸŽ€ SYNOPSIS πŸŽ€

type
typeof(expression);

πŸ¦‹ DESCRIPTION πŸ¦‹

Okay so the typeof() construct is the way you can obtain the type of an expression. Like, you feed it an expression and it gives you back the type. The syntax is comparable to that of sizeof(), but semantically typeof() operates like a type name defined with typedef. So it's giving sizeof energy syntax-wise but typedef energy meaning-wise β€” iykyk. πŸ’…


πŸ”₯ EXAMPLES πŸ”₯

The following is a typical example of a type-generic macro:

#define MAX(a, b) ({            \
        typeof(a) _a = (a);     \
        typeof(b) _b = (b);     \
        _a > _b ? _a : _b;      \
})

Like, the way this macro uses typeof(a) and typeof(b) to spin up local variables with the exact right types? Obsessed. So clean. So extra. Periodt. ✨


🌈 SEE ALSO 🌈

All iconic, all worth a lil vibe check. πŸ’–


πŸ’€ CAVEATS πŸ’€

Real talk: the typeof() construct is a non-standard, compiler-specific extension. So like, don't assume every compiler is gonna know what you're talking about, bestie. It's not standard C β€” it's a GCC thing. No cap. πŸ™ˆ


xoxo, this page was brought to you by Debian on December 19, 2010 πŸ’–βœ¨πŸŽ€ slay.

πŸ“¦ where this page comes from