473,513 Members | 2,275 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

mixing C and C++

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++ ??
May 28 '07 #1
2 1435
On 5月28日, 下午8时10分, S awek Tajnert <slawektajn....@interia.plwrote:
/* 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

May 28 '07 #2
kingfox wrote:
On 5鏈28鏃, 涓嬪崍8鏃10鍒, S awek Tajnert <slawektajn...@interia.plwrote:
>/* 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
May 28 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3306
by: bergel | last post by:
Hello, Does anyone already have some experience in mixing AWT and Swing? Is it conceptually doable? Does the design of Swing prevent interaction between an AWT and a Swing widget? Regards,...
6
4893
by: Russell E. Owen | last post by:
At one time, mixing for x in file and readline was dangerous. For example: for line in file: # read some lines from a file, then break nextline = readline() # bad would not do what a naive...
0
1807
by: Erik Max Francis | last post by:
Is there any prohibition against mixing different protocols within the same pickle? I don't see anything about this in the Python Library Reference and, after all, the pickle.dump function takes a...
4
23614
by: Rudolf | last post by:
Is it possible to add a vb.net source code module to a c# project and if so how? Thanks Rudolf
1
3395
by: Marc Cromme | last post by:
I would like to ask a question about (good ?) style and possibilities in mixing C FILE* and C++ file streams. The background is that I want to use the C libpng library from within C++, but I...
4
1916
by: Cristian Tota | last post by:
Hi, I'd appreciate any thoughts on mixing C++ and C code. I have a project that uses a given C interface, the rest of the project can be either in C or C++. What would be the recomended design...
2
2415
by: Dan | last post by:
Hi What are the dangers of mixing asp and asp.net? For the .net part of the site i will need to use the global.asax file but for the asp parts it will be using the other global. file, is there...
0
1256
by: dhruba.bandopadhyay | last post by:
I know that it's possible to mix ASP & ASP.NET 1.1 in the same website/application so long as they are in separate frames (iframes). This also holds for mixing ASP & ASP.NET 2.0 pages. But what I...
28
3035
by: ziman137 | last post by:
Hello all, I have a question and am seeking for some advice. I am currently working to implement an algorithmic library. Because the performance is the most important factor in later...
3
2082
by: jason | last post by:
I've been working with C# for over a year now without touching vb.net code. I had a few light years of vb.net before that. No real vb6 or windows form experience. Suddenly, I have an assignment...
0
7265
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7388
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7547
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7114
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5693
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project梡lanning, coding, testing,...
0
4751
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3240
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3230
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1607
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.