File: cabi2.cpp

package info (click to toggle)
gcc-arm-none-eabi 15%3A12.2.rel1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 959,712 kB
  • sloc: cpp: 3,275,382; ansic: 2,061,766; ada: 840,956; f90: 208,513; makefile: 76,132; asm: 73,433; xml: 50,448; exp: 34,146; sh: 32,436; objc: 15,637; fortran: 14,012; python: 11,991; pascal: 6,787; awk: 4,779; perl: 3,054; yacc: 338; ml: 285; lex: 201; haskell: 122
file content (254 lines) | stat: -rw-r--r-- 4,168 bytes parent folder | download | duplicates (2)
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254

#include <assert.h>
#include <stdio.h>
#include <stdint.h>

#if __cplusplus
extern "C" {
#endif

struct Foo1 { char c; };

struct Foo1 ctest1()
{
    struct Foo1 f;

    f.c = 3;
    return f;
}

struct Foo2 { short s; };

struct Foo2 ctest2()
{
    struct Foo2 f;

    f.s = 0x1234;
    return f;
}

struct Foo3 { char c; short s; };

struct Foo3 ctest3()
{
    struct Foo3 f;

    f.s = 0x5678;
    return f;
}


struct Foo4 { int i; };

struct Foo4 ctest4()
{
    struct Foo4 f;

    f.i = 0x12345678;
    return f;
}

struct Foo5 { int i, j; };

struct Foo5 ctest5()
{
    struct Foo5 f;

    f.i = 0x12345678;
    f.j = 0x21436587;
    return f;
}


struct Foo6 { int i, j, k; };

struct Foo6 ctest6()
{
    struct Foo6 f;

    f.i = 0x12345678;
    f.j = 0x21463587;
    f.k = 0x24163857;
    return f;
}

struct S7 { float a,b; };

struct S7 ctest10()
{
    struct S7 f;

    f.a = 2.5;
    f.b = 1.5;
    return f;
}

// =================================

char ctest7(char c)
{
    return c + 1;
}

unsigned char ctest8(unsigned char c)
{
    return c + 1;
}

signed char ctest9(signed char c)
{
    return c + 1;
}

/***********************************************/

void ctestrir(int x1, int x2, int x3, int x4, int x5, int x6, long double a, int b, long double c)
{
    assert(a == 100.0);
    assert(b == 67);
    assert(c == 200.0);
}

/***********************************************/

extern void dtestrir(int x1, int x2, int x3, int x4, int x5, int x6, long double a, int b, long double c);

void test4()
{
    dtestrir(1,2,3,4,5,6, 300.0, 68, 401.0);
}

/**********************************************/

typedef struct S11 {
  char a;
  char b;
  char c;
} S11;

S11 ctest11(char x, S11 s, char y) {
  printf("C sz = %d\n", (int)sizeof(S11));
  assert(sizeof(S11) == 3);
  printf("x   = %d\n", (int)x);
  printf("s.a = %d\n", (int)s.a);
  printf("s.b = %d\n", (int)s.b);
  printf("s.c = %d\n", (int)s.c);
  printf("y   = %d\n", (int)y);
  return s;
}

/**********************************************/

typedef struct S12 {
  char a,d;
  char b,e;
  char c;
} S12;

S12 ctest12(char x, S12 s, char y) {
  printf("C sz = %d\n", (int)sizeof(S12));
  assert(sizeof(S12) == 5);
  printf("x   = %d\n", (int)x);
  printf("s.a = %d\n", (int)s.a);
  printf("s.b = %d\n", (int)s.b);
  printf("s.c = %d\n", (int)s.c);
  printf("y   = %d\n", (int)y);
  return s;
}


/**********************************************/

typedef struct S13 {
  short a;
  short b;
  short c;
} S13;

S13 ctest13(char x, S13 s, char y) {
  printf("C sz = %d\n", (int)sizeof(S13));
  assert(sizeof(S13) == 6);
  printf("x   = %d\n", (int)x);
  printf("s.a = %d\n", (int)s.a);
  printf("s.b = %d\n", (int)s.b);
  printf("s.c = %d\n", (int)s.c);
  printf("y   = %d\n", (int)y);
  return s;
}


/**********************************************/

typedef struct S14 {
  char a,d,e,f;
  char b,g;
  char c;
} S14;

S14 ctest14(char x, S14 s, char y) {
  printf("C sz = %d\n", (int)sizeof(S14));
  assert(sizeof(S14) == 7);
  printf("x   = %d\n", (int)x);
  printf("s.a = %d\n", (int)s.a);
  printf("s.b = %d\n", (int)s.b);
  printf("s.c = %d\n", (int)s.c);
  printf("y   = %d\n", (int)y);
  return s;
}


/**********************************************/

typedef struct S15 {
  char a,d,e,f;
  char b,g,h,i;
  char c;
} S15;

S15 ctest15(char x, S15 s, char y) {
  printf("C sz = %d\n", (int)sizeof(S15));
  assert(sizeof(S15) == 9);
  printf("x   = %d\n", (int)x);
  printf("s.a = %d\n", (int)s.a);
  printf("s.b = %d\n", (int)s.b);
  printf("s.c = %d\n", (int)s.c);
  printf("y   = %d\n", (int)y);
  return s;
}


/**********************************************/

typedef struct S16 {
  char a[5];
#ifdef __GNUC__
  struct __attribute__((packed))
#else
  #pragma pack(push, 1)
  struct
#endif
  {
    char b;
    int c;
  };
#ifndef __GNUC__
  #pragma pack(pop)
#endif
} S16;

S16 ctest16(char x, S16 s, char y) {
  printf("C sz = %d\n", (int)sizeof(S16));
  assert(sizeof(S16) == 10);
  printf("x   = %d\n", (int)x);
  printf("s.a = %.*s\n", 5, s.a);
  printf("s.b = %d\n", (int)s.b);
  printf("s.c = %d\n", s.c);
  printf("y   = %d\n", (int)y);
  return s;
}



#if __cplusplus
}
#endif