File: uniondef.pl

package info (click to toggle)
libffi-c-perl 0.15-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 484 kB
  • sloc: perl: 1,517; ansic: 57; sh: 19; makefile: 2
file content (24 lines) | stat: -rw-r--r-- 486 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
use strict;
use warnings;
use FFI::Platypus 1.00;
use FFI::C::UnionDef;

my $ffi = FFI::Platypus->new( api => 1 );
# See FFI::Platypus::Bundle for how bundle works.
$ffi->bundle;

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

$ffi->attach( print_anyint_as_u32 => ['anyint_t'] );

my $int = AnyInt->new({ u8 => 42 });
print_anyint_as_u32($int);  # 0x2a on Intel,