__BUILTIN_CONSTANT_P(3)

πŸ“¦ version 11.0, in nixpkgs unstable

πŸ‘‘ NAME β€” __builtin_constant_p(3) πŸ‘‘

okay so hey bestie πŸ’–, you're in the Library Functions Manual, and the queen of this page is __builtin_constant_p β€” a GNU extension to determine compile time constants ✨. That's literally the whole vibe.


πŸ¦‹ SYNOPSIS πŸ¦‹

int
__builtin_constant_p(value);

πŸ’… DESCRIPTION πŸ’…

Okay so __builtin_constant_p() is a GNU extension for determining whether a value is known to be constant at compile time 🧚. It's closely related to the concept of β€œconstant folding” used by modern optimizing compilers ✨.

If the value is known to be a compile-time constant, a value 1 is returned πŸ”₯. If __builtin_constant_p() returns 0, the value is not a compile-time constant in the sense that gcc(1) was unable to determine whether the value is constant or not 😭. Periodt.


🌸 EXAMPLES 🌸

A typical example of the use of __builtin_constant_p() involves a situation where it may be desirable to fold the computation if it involves a constant, but a function call is needed otherwise 🫢. For instance, bswap16(3) is defined in NetBSD as:

#define bswap16(x) \
        (__builtin_constant_p((x)) ? \
         __byte_swap_u16_constant(x) : __BYTE_SWAP_U16_VARIABLE(x))

πŸ‘€ SEE ALSO πŸ‘€


⚠️ CAVEATS ⚠️

bestie, this is a non-standard, compiler-specific extension πŸ’€. That's the caveat, no cap.

source: Debian πŸ’‹ β€” this page is dated December 19, 2010 πŸŽ€. stay iconic, bestie πŸ’–

πŸ“¦ where this page comes from