xref: /php-src/ext/ffi/tests/031.phpt (revision 4acf0084)
1--TEST--
2FFI 031: bit-fields packing
3--EXTENSIONS--
4ffi
5--INI--
6ffi.enable=1
7--FILE--
8<?php
9function test_size($expected_size, $type) {
10    try {
11        $size = FFI::sizeof(FFI::cdef()->new($type));
12        if ($size !== $expected_size) {
13            echo "FAIL: sizeof($type) != $expected_size ($size)\n";
14        }
15    } catch (Throwable $e) {
16        echo $type . "=>" . get_class($e) . ": " . $e->getMessage()."\n";
17    }
18}
19
20test_size( 4, "struct {int a:2; int b:2;}");
21test_size( 1, "struct __attribute__((packed)) {int a:2; int b:2;}");
22test_size( 8, "struct {int a:2; unsigned long long :60; int b:2;}");
23test_size( 9, "struct __attribute__((packed)) {int a:2; unsigned long long :64; int b:2;}");
24test_size( 4, "union {int a:2; int b:8;}");
25test_size( 1, "union __attribute__((packed)) {int a:2; int b:8;}");
26?>
27ok
28--EXPECT--
29ok
30