File: union.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 (16 lines) | stat: -rw-r--r-- 294 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
use strict;
use warnings;
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