forked from HiwarkhedePrasad/ByteWise
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_cases.c
More file actions
62 lines (53 loc) · 1.05 KB
/
test_cases.c
File metadata and controls
62 lines (53 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <stddef.h>
// 1. Flexible Array Member
struct Flex {
size_t len;
char data[]; // Should be size 0
};
// 2. Packed Struct with Pragma
#pragma pack(push, 1)
struct PackedP {
char a;
int b;
char c;
};
#pragma pack(pop)
// 3. Anonymous Struct & Union
struct WithAnon {
struct { int a; char b; } anon;
union { int u1; double u2; };
char tail;
};
// 4. Bitfields
struct BitFields {
int a : 3;
int b : 5;
int c : 24; // Total 32 bits = 4 bytes
int : 0; // Reset
unsigned long long d : 1; // New storage unit (8 bytes)
};
// 5. Inline Struct
struct InlineDecl {
struct Embedded { int e; char f; } emb;
} inline_inst;
// 6. Packed Attribute
struct PackedAttr {
char a;
int b;
char c;
} __attribute__((packed));
// 7. Union
union U {
struct { char a; int b; } s;
double d;
};
// 8. Aligned Attribute
struct AlignTest {
char a;
int b __attribute__((aligned(16)));
char c;
} __attribute__((aligned(8)));
// 9. Multi-dimensional Array
struct ArrayTest {
int matrix[3][2];
};