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
|
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil -*-
*
* libfsbv.c --- auxiliary C lib for testing foreign structure by value calls
*
* Copyright (C) 2011, 2015 Liam M. Healy
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#ifdef WIN32
#define DLLEXPORT __declspec(dllexport)
#else
#define DLLEXPORT
#endif
#include <stdio.h>
#include <limits.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>
#include <float.h>
/* MSVC doesn't have stdint.h and uses a different syntax for stdcall */
#ifndef _MSC_VER
#include <stdint.h>
#endif
#ifdef WIN32
#ifdef _MSC_VER
#define STDCALL __stdcall
#else
#define STDCALL __attribute__((stdcall))
#endif
#else
#define STDCALL
#endif
struct struct_pair {
int a;
int b;
};
struct struct_pair_double {
struct struct_pair pr;
double dbl;
};
typedef enum {
ONE = 1,
TWO,
THREE,
FOUR,
FORTY_ONE = 41,
FORTY_TWO
} numeros;
int sumpair (struct struct_pair sp);
int enumpair (numeros mynum, struct struct_pair sp);
struct struct_pair doublepair (struct struct_pair dp);
double prodsumpair (struct struct_pair_double spd);
struct struct_pair_double doublepairdouble (struct struct_pair_double pd);
DLLEXPORT
int sumpair (struct struct_pair sp)
{
return sp.a + sp.b;
}
DLLEXPORT
int enumpair (numeros mynum, struct struct_pair sp)
{
if ( mynum == ONE )
{
return sp.a + sp.b;
}
else if ( mynum == TWO )
{
return sp.a + 2*sp.b;
}
else if ( mynum == THREE )
{
return 2*sp.a + sp.b;
}
else if ( mynum == FOUR )
{
return 2*sp.a + 2*sp.b;
}
else
{
return 41*sp.a + 42*sp.b;
}
}
DLLEXPORT
struct struct_pair makepair (bool cond)
{
struct struct_pair ret;
ret.a = -127;
ret.b = cond ? 42 : 43;
return ret;
}
const struct struct_pair static_pair = { 40, 2};
DLLEXPORT
struct struct_pair * returnpairpointer (struct struct_pair ignored)
{
return &static_pair;
}
DLLEXPORT
struct struct_pair doublepair (struct struct_pair dp)
{
struct struct_pair ret;
ret.a = 2*dp.a;
ret.b = 2*dp.b;
return ret;
}
DLLEXPORT
double prodsumpair (struct struct_pair_double pd)
{
return pd.dbl * sumpair(pd.pr);
}
DLLEXPORT
struct struct_pair_double doublepairdouble (struct struct_pair_double pd)
{
struct struct_pair_double ret;
ret.pr = doublepair(pd.pr);
ret.dbl = 2*pd.dbl;
return ret;
}
DLLEXPORT
unsigned long long ullsum (unsigned long long a, unsigned long long b)
{
return a + b;
}
DLLEXPORT
struct struct_pair stringlenpair (char *string, struct struct_pair dp)
{
struct struct_pair ret;
int len = strlen(string);
ret.a = len*dp.a;
ret.b = len*dp.b;
return ret;
}
struct bitfield_struct {
unsigned int b;
};
DLLEXPORT
struct bitfield_struct structbitfield (unsigned int x) {
struct bitfield_struct ret;
ret.b = x;
return ret;
}
|