infix
A JIT-Powered FFI Library for C
Loading...
Searching...
No Matches
009_bitfields_fam.c File Reference

Unit test for Bitfields and Flexible Array Members (FAM). More...

#include "common/double_tap.h"
#include <infix/infix.h>
#include <stddef.h>
#include <stdint.h>
Include dependency graph for 009_bitfields_fam.c:

Classes

struct  StructWithFAM
 
struct  BitfieldStruct1
 
struct  BitfieldStructOverflow
 
struct  BitfieldStructZeroWidth
 

Macros

#define DBLTAP_IMPLEMENTATION
 

Functions

 subtest ("Flexible Array Members (FAM)")
 
 subtest ("Bitfields")
 
 infix_arena_destroy (arena)
 

Variables

 TEST
 
infix_arena_tarena = infix_arena_create(4096)
 

Detailed Description

Unit test for Bitfields and Flexible Array Members (FAM).

This test verifies the functionality of two advanced C type features:

  1. Flexible Array Members:
    • Tests the [?:type] signature syntax.
    • Tests the infix_type_create_flexible_array Manual API.
    • Verifies that the struct layout (size and offsets) correctly handles the FAM (i.e., it adds no size to the struct but respects alignment).
  2. Bitfields:
    • Tests the name:type:width signature syntax.
    • Tests the infix_type_create_bitfield_member Manual API.
    • Verifies packing of uint8_t bitfields.
    • Verifies the behavior of zero-width bitfields for alignment forcing.
Note
The current implementation of bitfields primarily supports byte-granular packing (typical of uint8_t flags). Complex packing of larger integers across byte boundaries (e.g., uint32_t) is implementation-defined in C and currently simplified in infix to flush to the next byte on overflow.

Macro Definition Documentation

◆ DBLTAP_IMPLEMENTATION

#define DBLTAP_IMPLEMENTATION

Function Documentation

◆ infix_arena_destroy()

infix_arena_destroy ( arena  )

◆ subtest() [1/2]

subtest ( "Bitfields"  )

◆ subtest() [2/2]

subtest ( "Flexible Array Members (FAM)"  )

Variable Documentation

◆ arena

◆ TEST

TEST
Initial value:
{
plan(2)
#define plan(count)
Definition double_tap.h:154