FFI::C::Union(3pm)

πŸ’– FFI::C::Union πŸ’–

okay bestie, welcome to FFI::C::Union β€” the Perl module that's literally the union data instance for FFI, from the User Contributed Perl Documentation section of your man pages (section 3pm, iykyk). this is version 0.15 and she is serving ✨


πŸ¦‹ SYNOPSIS πŸ¦‹

here's the whole vibe, copy-paste ready, no cap:

use FFI::C::UnionDef;

my $def = FFI::C::UnionDef->new(
  name => 'anyint_t',
  class => 'AnyInt',
  members => [
    u8  => 'uint8',
    u16 => 'uint16',
    u32 => 'uint32',
  ],
);

my $int = AnyInt->new({ u8 => 42 });
printf "0x%x\n", $int->u32;   # 0x2a on Intel

see that last line? 0x2a on Intel. that's the union doing union things 🫢


🌸 DESCRIPTION 🌸

so this class represents an instance of a C union. that's the whole main character energy of the file. πŸ’…

how do you even get one? two ways, bestie:

  • you can create it using new on the generated class β€” but only if that class was specified for the FFI::C::UnionDef
  • or you can use the create method over on FFI::C::UnionDef

and here's the iconic part: for each member defined in the FFI::C::UnionDef, there's an accessor for the FFI::C::Union instance. every single one. no member left behind πŸŽ€


🧚 CONSTRUCTOR 🧚

✨ new ✨

FFI::C::UnionDef->new( class => 'User::Union::Class', ... );
my $instance = User::Union::Class->new;

creates a new instance of the union. that's it, that's the job, and she ate πŸ”₯


πŸ‘‘ SEE ALSO πŸ‘‘

go read these too, they're all part of the friend group:

  • FFI::C
  • FFI::C::Array
  • FFI::C::ArrayDef
  • FFI::C::Def
  • FFI::C::File
  • FFI::C::PosixFile
  • FFI::C::Struct
  • FFI::C::StructDef
  • FFI::C::Union
  • FFI::C::UnionDef
  • FFI::C::Util
  • FFI::Platypus::Record

πŸ’œ AUTHOR πŸ’œ

Graham Ollis <plicease@cpan.org> β€” absolute legend, we stan 🫢


This software is copyright (c) 2020-2022 by Graham Ollis.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.


ok so that's the whole page bestie, go forth and union πŸ’–

and that's a wrap! this page came to you from perl v5.36.0, dated 2023-02-06, filed under FFI::C::Union(3pm) β€” mwah, slay, periodt βœ¨πŸŽ€πŸ’…

πŸ“¦ where this page comes from