mixing C and C++

  • Thread starter =?ISO-8859-2?Q?S=B3awek_Tajnert?=
  • Start date
?

=?ISO-8859-2?Q?S=B3awek_Tajnert?=

Hi.

I'm trying add function in C to code C++:

In file photo.cpp I have:

#include "photo.hpp"

#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <cmath>

extern "C" {
int emocje(float *in, float *out, int init)
#include "emocje.h"
}

..
..
..


and I get (in Dev++):
61 C:\emocje\emocje.c redefinition of `UnitType Units[18]'
24 C:\emocje\emocje.c `UnitType Units[18]' previously declared here


and this is file emocje.cpp, generated by snns2c (neural networks SNNS):

#include <math.h>

#define Act_Logistic(sum, bias) ( (sum+bias<10000.0) ? ( 1.0/(1.0 +
exp(-sum-bias) ) ) : 0.0 )
#ifndef NULL
#define NULL (void *)0
#endif

typedef struct UT {
float act; /* Activation */
float Bias; /* Bias of the Unit */
int NoOfSources; /* Number of predecessor units */
struct UT **sources; /* predecessor units */
float *weights; /* weights from predecessor units */
} UnitType, *pUnit;

/* Forward Declaration for all unit types */
static UnitType Units[18];

/* Sources definition section */
static pUnit Sources[] = {
Units + 1, Units + 2, Units + 3, Units + 4, Units + 5, Units + 6, Units
+ 7, Units + 8, Units + 9, Units + 10,

Units + 1, Units + 2, Units + 3, Units + 4, Units + 5, Units + 6, Units
+ 7, Units + 8, Units + 9, Units + 10,

Units + 1, Units + 2, Units + 3, Units + 4, Units + 5, Units + 6, Units
+ 7, Units + 8, Units + 9, Units + 10,

Units + 1, Units + 2, Units + 3, Units + 4, Units + 5, Units + 6, Units
+ 7, Units + 8, Units + 9, Units + 10,

Units + 1, Units + 2, Units + 3, Units + 4, Units + 5, Units + 6, Units
+ 7, Units + 8, Units + 9, Units + 10,

Units + 11, Units + 12, Units + 13, Units + 14, Units + 15,
Units + 11, Units + 12, Units + 13, Units + 14, Units + 15,

};

/* Weigths definition section */
static float Weights[] = {
9.888870, -2.209920, -2.139630, 0.634080, 3.348530, -12.600170,
-1.217220, 0.079510, 15.213780, 10.708130,

15.226140, -1.183220, -3.153110, 0.266690, 0.520140, 2.480400, 6.945020,
0.695290, 15.829990, 16.931850,

14.590910, -3.775820, 0.117690, 0.230650, -2.176640, 7.371670, 9.442880,
-1.915540, 14.002770, 16.404301,

15.019070, -1.290780, -4.441600, 0.293980, -0.645350, 4.382700,
6.934660, 0.554830, 14.879510, 16.850611,

14.085470, 5.345510, -12.129450, 0.507580, 3.062340, -4.056810,
2.457100, 7.250320, 15.397990, 15.686710,

12.503120, 9.661680, 9.316230, 9.441750, 10.546040,
-12.503120, -9.661660, -9.316200, -9.441810, -10.546030,

};

/* unit definition section (see also UnitType) */
static UnitType Units[18] =
{
{ 0.0, 0.0, 0, NULL , NULL },
{ /* unit 1 (Old: 1) */
0.0, 1.000000, 0,
&Sources[0] ,
&Weights[0] ,
},
{ /* unit 2 (Old: 2) */
0.0, 0.999980, 0,
&Sources[0] ,
&Weights[0] ,
},
{ /* unit 3 (Old: 3) */
0.0, 0.999990, 0,
&Sources[0] ,
&Weights[0] ,
},
{ /* unit 4 (Old: 4) */
0.0, 0.999980, 0,
&Sources[0] ,
&Weights[0] ,
},
{ /* unit 5 (Old: 5) */
0.0, 0.999980, 0,
&Sources[0] ,
&Weights[0] ,
},
{ /* unit 6 (Old: 6) */
0.0, 0.999990, 0,
&Sources[0] ,
&Weights[0] ,
},
{ /* unit 7 (Old: 7) */
0.0, 0.999990, 0,
&Sources[0] ,
&Weights[0] ,
},
{ /* unit 8 (Old: 8) */
0.0, 0.999970, 0,
&Sources[0] ,
&Weights[0] ,
},
{ /* unit 9 (Old: 9) */
0.0, 0.999970, 0,
&Sources[0] ,
&Weights[0] ,
},
{ /* unit 10 (Old: 10) */
0.0, 0.999980, 0,
&Sources[0] ,
&Weights[0] ,
},
{ /* unit 11 (Old: 11) */
0.0, 3.061640, 10,
&Sources[0] ,
&Weights[0] ,
},
{ /* unit 12 (Old: 12) */
0.0, -5.441660, 10,
&Sources[10] ,
&Weights[10] ,
},
{ /* unit 13 (Old: 13) */
0.0, -4.108320, 10,
&Sources[20] ,
&Weights[20] ,
},
{ /* unit 14 (Old: 14) */
0.0, -4.975150, 10,
&Sources[30] ,
&Weights[30] ,
},
{ /* unit 15 (Old: 15) */
0.0, -3.668400, 10,
&Sources[40] ,
&Weights[40] ,
},
{ /* unit 16 (Old: 16) */
0.0, -21.453300, 5,
&Sources[50] ,
&Weights[50] ,
},
{ /* unit 17 (Old: 17) */
0.0, 21.453291, 5,
&Sources[55] ,
&Weights[55] ,
}

};



int emocje(float *in, float *out, int init)
{
int member, source;
float sum;
enum{OK, Error, Not_Valid};
pUnit unit;


/* layer definition section (names & member units) */

static pUnit Input[10] = {Units + 1, Units + 2, Units + 3, Units + 4,
Units + 5, Units + 6, Units + 7, Units + 8, Units + 9, Units + 10}; /*
members */

static pUnit Hidden1[5] = {Units + 11, Units + 12, Units + 13, Units
+ 14, Units + 15}; /* members */

static pUnit Output1[2] = {Units + 16, Units + 17}; /* members */

static int Output[2] = {16, 17};

for(member = 0; member < 10; member++) {
Input[member]->act = in[member];
}

for (member = 0; member < 5; member++) {
unit = Hidden1[member];
sum = 0.0;
for (source = 0; source < unit->NoOfSources; source++) {
sum += unit->sources[source]->act
* unit->weights[source];
}
unit->act = Act_Logistic(sum, unit->Bias);
};

for (member = 0; member < 2; member++) {
unit = Output1[member];
sum = 0.0;
for (source = 0; source < unit->NoOfSources; source++) {
sum += unit->sources[source]->act
* unit->weights[source];
}
unit->act = Act_Logistic(sum, unit->Bias);
};

for(member = 0; member < 2; member++) {
out[member] = Units[Output[member]].act;
}

return(OK);
}
*******************************************************************************

this is file emocje.h, also generated by snns2c:

extern int emocje(float *in, float *out, int init);

static struct {
int NoOfInput; /* Number of Input Units */
int NoOfOutput; /* Number of Output Units */
int(* propFunc)(float *, float*, int);
} emocjeREC = {10,2,emocje};


How add this function to code C++ ??
 
K

kingfox

/* Forward Declaration for all unit types */
static UnitType Units[18];
Delete this line.
this is file emocje.h, also generated by snns2c:

extern int emocje(float *in, float *out, int init);
#ifdef __cplusplus
extern "C" int emocje(float *in, float *out, int init);
#endif // __cplusplus
 
G

Guest

kingfox said:
/* Forward Declaration for all unit types */
static UnitType Units[18];
Delete this line.
this is file emocje.h, also generated by snns2c:

extern int emocje(float *in, float *out, int init);
#ifdef __cplusplus
extern "C" int emocje(float *in, float *out, int init);
#endif // __cplusplus

I can't delete line
static UnitType Units[18];

because lower is definition, with contain Units[]

/* Sources definition section */
static pUnit Sources[] = {
Units + 1, Units + 2
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,152
Members
46,697
Latest member
AugustNabo

Latest Threads

Top