1--TEST-- 2FFI 032: bit-fields access 3--SKIPIF-- 4<?php require_once('skipif.inc'); ?> 5--INI-- 6ffi.enable=1 7--FILE-- 8<?php 9$p = FFI::new(" 10 union { 11 struct __attribute__((packed)) { 12 int a:2; 13 unsigned long long b:64; 14 int c:3; 15 unsigned int d:3; 16 } s; 17 uint8_t i[9]; 18}"); 19var_dump(FFI::sizeof($p)); 20for ($i = -5; $i < 9; $i++) { 21 $p->s->c = $i; 22 $p->s->d = $i; 23 echo "$i => 3-bit int {$p->s->c}, 3-bit uint {$p->s->d}\n"; 24} 25$p->s->a = 0; 26$p->s->c = 0; 27$p->s->d = 0; 28$p->s->b = 0x7fffffff; 29echo "0x"; 30for ($i = 9; $i > 0;) { 31 printf("%02x", $p->i[--$i]); 32} 33echo "\n"; 34?> 35ok 36--EXPECT-- 37int(9) 38-5 => 3-bit int 3, 3-bit uint 3 39-4 => 3-bit int -4, 3-bit uint 4 40-3 => 3-bit int -3, 3-bit uint 5 41-2 => 3-bit int -2, 3-bit uint 6 42-1 => 3-bit int -1, 3-bit uint 7 430 => 3-bit int 0, 3-bit uint 0 441 => 3-bit int 1, 3-bit uint 1 452 => 3-bit int 2, 3-bit uint 2 463 => 3-bit int 3, 3-bit uint 3 474 => 3-bit int -4, 3-bit uint 4 485 => 3-bit int -3, 3-bit uint 5 496 => 3-bit int -2, 3-bit uint 6 507 => 3-bit int -1, 3-bit uint 7 518 => 3-bit int 0, 3-bit uint 0 520x0000000001fffffffc 53ok 54