TYPEOF(3)
β¨ 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
- nixpkgs unstable: netbsd-source 11.0
- Copyright (c) 2010 Jukka Ruohonen <jruohonen@iki.fi>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms