Juan Bravo Juan Bravo - 4 months ago 22
C Question

Error declaring a function

This is a header file. But when I include it in the main.c it give me the next error: expected identifier or '(' before 'float'. I know it can be a very stupid error but i don't see it. The code is:

#ifndef Reference
#define Reference
float mat_a[3][3];
struct Reference_XS
{
int Bytes;
unsigned char *Buffer_Lectura;
};
struct Reference_XS Sist_Referecence(float q0,float q1,float q2,float q3,float val1,float val2,float val3)
{
float mat_a={(2*q0*q0)+(2*q1*q1)-1, (2*q1*q2)-(2*q0*q3), 2*q1*q3)+(2*q0*q1), (2*q1*q2)+(2*q0*q3), (2*q0*q0+(2*q2*q2)-1), (2*q2*q3)-(2*q0*q1), (2*q1*q3)-(2*q0*q2), (2*q2*q3)+(2*q0*q1), (2*q0*q0)+(2*q3*q3)-1};
float mat_b[3][1]={val1,val2,val3};
float mat_c[3][1];
int i,k;
float temp=0;
for(i=0;i<3;i++)
{
temp=0;
for(k=0;k<3;k++)
{
temp=mat_a[i][k]*mat_b[k][0]+temp;
mat_c[i][0]=temp;
}
}
struct Reference_XS data={mat_c};
return data;
}
#endif

Answer

In this statement

float mat_a={(2*q0*q0)+(2*q1*q1)-1, (2*q1*q2)-(2*q0*q3), 2*q1*q3)+(2*q0*q1), (2*q1*q2)+(2*q0*q3), (2*q0*q0+(2*q2*q2)-1), (2*q2*q3)-(2*q0*q1), (2*q1*q3)-(2*q0*q2), (2*q2*q3)+(2*q0*q1), (2*q0*q0)+(2*q3*q3)-1};

you are trying to initialize a scalar object with multiple initializers and moreover the third initializer dors not have the open parenthesis

2*q1*q3)+(2*q0*q1),

^^^

It seems you wanted to define an array with the name mat_a instead of the scalar object.

Comments