__BUILTIN_TYPES_COMPATIBLE_P(3)

πŸ“¦ version 11.0, in nixpkgs unstable

πŸ’– __builtin_types_compatible_p(3) β€” GNU extension to check equivalent types πŸ’–

okay bestie, welcome to the Library Functions Manual β€” today’s main character is __builtin_types_compatible_p(3), and it’s literally here to check if two types are equivalent. no cap. πŸ’…


✨ NAME ✨

__builtin_types_compatible_p β€” the GNU extension that checks whether two types are equivalent. 🫢


🌸 SYNOPSIS 🌸

call it like this, bestie:

int
__builtin_types_compatible_p(type_a, type_b);

πŸ¦‹ DESCRIPTION πŸ¦‹

__builtin_types_compatible_p() is a GNU extension for determining whether two types are equivalent. If type_a is equivalent to type_b, you get the value 1. Otherwise, __builtin_types_compatible_p() returns 0. that’s the whole vibe. ✨

The following remarks should be taken into account β€” think of them as the receipts you gotta keep in mind:

  1. The architecture-specific size of the two types does not have an impact on the result. For example, sizeof(char *) and sizeof(int) result the same value on i386, but the types naturally are not equivalent. 😭
  2. Type qualifiers are ignored. The function returns the same value for long and const long. πŸ’–
  3. The amount of pointer indirection affects the result. For example, double * is not equivalent to double **. πŸ”₯
  4. Two types defined with typedef are equivalent if and only if their underlying types are equivalent. πŸ‘‘
  5. The enum type is a special case in that two enum types are not considered equivalent. πŸ’€

πŸŽ€ EXAMPLES πŸŽ€

The following example combines __builtin_types_compatible_p() and the typeof(3) construct:

             #define __COMPARE_TYPES(v, t)      \
                      __builtin_types_compatible_p(__typeof__(v), t)

             ...

             if (__COMPARE_TYPES(p, double) != 0)
                     err(EX_DATAERR, "invalid type");

🌈 SEE ALSO 🌈

go give these a lil scroll too, bestie:


⭐ CAVEATS ⭐

Caveat, fr fr: This is a non-standard, compiler-specific extension. πŸ’…

Debian β€’ December 21, 2010 β€’ signing off on __builtin_types_compatible_p(3) β€” mwah, bestie πŸ’–πŸ«Ά

πŸ“¦ where this page comes from