@@ -75,6 +75,24 @@ struct MedStructMixed {
7575void zig_med_struct_mixed (struct MedStructMixed );
7676struct MedStructMixed zig_ret_med_struct_mixed ();
7777
78+ struct SmallPackedStruct {
79+ uint8_t a : 2 ;
80+ uint8_t b : 2 ;
81+ uint8_t c : 2 ;
82+ uint8_t d : 2 ;
83+ uint8_t e : 1 ;
84+ };
85+
86+ struct BigPackedStruct {
87+ uint64_t a : 64 ;
88+ uint64_t b : 64 ;
89+ uint64_t c : 64 ;
90+ uint64_t d : 64 ;
91+ uint8_t e : 8 ;
92+ };
93+
94+ //void zig_small_packed_struct(struct SmallPackedStruct); // #1481
95+ void zig_big_packed_struct (struct BigPackedStruct );
7896
7997struct SplitStructInts {
8098 uint64_t a ;
@@ -137,6 +155,16 @@ void run_c_tests(void) {
137155 zig_small_struct_ints (s );
138156 }
139157
158+ {
159+ struct BigPackedStruct s = {1 , 2 , 3 , 4 , 5 };
160+ zig_big_packed_struct (s );
161+ }
162+
163+ {
164+ struct SmallPackedStruct s = {0 , 1 , 2 , 3 , 1 };
165+ //zig_small_packed_struct(s);
166+ }
167+
140168 {
141169 struct SplitStructInts s = {1234 , 100 , 1337 };
142170 zig_split_struct_ints (s );
@@ -318,6 +346,44 @@ void c_split_struct_mixed(struct SplitStructMixed x) {
318346 assert_or_panic (y .c == 1337.0f );
319347}
320348
349+ struct SmallPackedStruct c_ret_small_packed_struct () {
350+ struct SmallPackedStruct s = {
351+ .a = 0 ,
352+ .b = 1 ,
353+ .c = 2 ,
354+ .d = 3 ,
355+ .e = 1 ,
356+ };
357+ return s ;
358+ }
359+
360+ void c_small_packed_struct (struct SmallPackedStruct x ) {
361+ assert_or_panic (x .a == 0 );
362+ assert_or_panic (x .a == 1 );
363+ assert_or_panic (x .a == 2 );
364+ assert_or_panic (x .a == 3 );
365+ assert_or_panic (x .e == 1 );
366+ }
367+
368+ struct BigPackedStruct c_ret_big_packed_struct () {
369+ struct BigPackedStruct s = {
370+ .a = 1 ,
371+ .b = 2 ,
372+ .c = 3 ,
373+ .d = 4 ,
374+ .e = 5 ,
375+ };
376+ return s ;
377+ }
378+
379+ void c_big_packed_struct (struct BigPackedStruct x ) {
380+ assert_or_panic (x .a == 1 );
381+ assert_or_panic (x .b == 2 );
382+ assert_or_panic (x .c == 3 );
383+ assert_or_panic (x .d == 4 );
384+ assert_or_panic (x .e == 5 );
385+ }
386+
321387struct SplitStructMixed c_ret_split_struct_mixed () {
322388 struct SplitStructMixed s = {
323389 .a = 1234 ,
0 commit comments