1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil -*-
3 * libfsbv.c --- auxiliary C lib for testing foreign structure by value calls
5 * Copyright (C) 2011, 2015 Liam M. Healy
7 * Permission is hereby granted, free of charge, to any person
8 * obtaining a copy of this software and associated documentation
9 * files (the "Software"), to deal in the Software without
10 * restriction, including without limitation the rights to use, copy,
11 * modify, merge, publish, distribute, sublicense, and/or sell copies
12 * of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be
16 * included in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 * DEALINGS IN THE SOFTWARE.
29 #define DLLEXPORT __declspec(dllexport)
42 /* MSVC doesn't have stdint.h and uses a different syntax for stdcall */
49 #define STDCALL __stdcall
51 #define STDCALL __attribute__((stdcall))
62 struct struct_pair_double
{
63 struct struct_pair pr
;
76 int sumpair (struct struct_pair sp
);
77 int enumpair (numeros mynum
, struct struct_pair sp
);
78 struct struct_pair
doublepair (struct struct_pair dp
);
79 double prodsumpair (struct struct_pair_double spd
);
80 struct struct_pair_double
doublepairdouble (struct struct_pair_double pd
);
83 int sumpair (struct struct_pair sp
)
89 int enumpair (numeros mynum
, struct struct_pair sp
)
95 else if ( mynum
== TWO
)
99 else if ( mynum
== THREE
)
101 return 2*sp
.a
+ sp
.b
;
103 else if ( mynum
== FOUR
)
105 return 2*sp
.a
+ 2*sp
.b
;
109 return 41*sp
.a
+ 42*sp
.b
;
114 struct struct_pair
makepair (bool cond
)
116 struct struct_pair ret
;
118 ret
.b
= cond
? 42 : 43;
122 const struct struct_pair static_pair
= { 40, 2};
125 struct struct_pair
* returnpairpointer (struct struct_pair ignored
)
131 struct struct_pair
doublepair (struct struct_pair dp
)
133 struct struct_pair ret
;
140 double prodsumpair (struct struct_pair_double pd
)
142 return pd
.dbl
* sumpair(pd
.pr
);
146 struct struct_pair_double
doublepairdouble (struct struct_pair_double pd
)
148 struct struct_pair_double ret
;
149 ret
.pr
= doublepair(pd
.pr
);
155 unsigned long long ullsum (unsigned long long a
, unsigned long long b
)
161 struct struct_pair
stringlenpair (char *string
, struct struct_pair dp
)
163 struct struct_pair ret
;
164 int len
= strlen(string
);
170 struct bitfield_struct
{
175 struct bitfield_struct
structbitfield (unsigned int x
) {
176 struct bitfield_struct ret
;