__UNCONST(3)
β¨ __UNCONST β the compile-time cast-away macro, bestie edition β¨
okay so picture this: you're in __UNCONST(3) from the Library Functions Manual, and honestly? it's giving "tiny macro, big drama." let's get into it π
πΈ NAME πΈ
__UNCONST β a compile time cast-away macro. yes, it literally casts away your const at compile time. no cap. π«Ά
π SYNOPSIS π
#include <sys/cdefs.h>
void
__UNCONST(x);
void
__UNVOLATILE(x);
two little functions-looking things, one iconic header. slay. β¨
π DESCRIPTION π
so here's the vibe check: the __UNCONST() macro is your go-to when you wanna omit warnings that certain compilers throw at you when you're operating with pointers declared with the const type qualifier in a context that doesn't have that qualifier. messy, i know. π
the classic examples, bestie:
- passing a pointer declared with the
constqualifier to a function that doesn't have such a qualifier - variable assignment from a
constpointer to a non-constpointer
and in the same vein β like, same energy, same family β the __UNVOLATILE() macro can be used to exclude warnings related to the volatile type qualifier. it ate, honestly. π₯
π§ IMPLEMENTATION NOTES π§
these macros are implemented by explicitly using unsigned long instead of intptr_t. and lowkey important: intptr_t is a signed type guaranteed to hold a pointer. so yeah, they chose the unsigned one on purpose. iykyk. π
π¦ SEE ALSO π¦
go read those, bestie, they're part of the lore. π
π CAVEATS π
okay this is the part where we get serious for a sec, because this is highkey a big deal:
both macros may hide valid errors, so their usage is not recommended unless there is a well-thought reason for a cast. like, an actual reason. not just "the compiler was being annoying." π
- a typical use case for
__UNCONST()involves an API that does not follow the so-called ``const correctness'' β even if it would be appropriate. yes, we're all side-eyeing that API. π - valid use cases of
__UNVOLATILE()include passing avolatilepointer tomemset(3).
also, and this is important: use of this macro is non-portable. it's part of the implementation namespace and should only be used in NetBSD code. periodt. π
β the cute sign-off β
this little page came from Debian, dated October 17, 2013, and it's filed under __UNCONST(3). that's the whole footer, bestie β no notes, no cap, iconic behavior. πππ
π¦ where this page comes from
- nixpkgs unstable: netbsd-source 11.0
- Copyright (c) 2010 The NetBSD Foundation, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms