Go Down

Topic: initializing an array of floats within a structure during declaration. (Read 2449 times) previous topic - next topic

astrofrostbyte

Apr 01, 2011, 04:35 pm Last Edit: Apr 01, 2011, 04:39 pm by astrofrostbyte Reason: 1
Hi , I´m having trouble initializing an array of floats within a structure during declaration.

Code: [Select]

struct CalibParam {                    // Calibration Parameters aX^2 + bX + c
 float a;
 float b;
 float c;  
} ;
struct AnalogSensors {
  CalibParam CalPar[4] ;     // E2P array of structures ex: an.CalPar.b
  int  SurfTemp;
  // ... snip
  int  BarPres;
  long avgarray[4];
} an = { {0.0 , 5000.0/1024.0 , 0.0 } ,
        {0.0 , 5000.0/1024.0 , 0.0 } ,
        {0.0 , 1.0 , 0.0 },
        {0.0 , 1.0 , 0.0 } };

Gives : error: braces around scalar initializer for type 'int'
I´ve tried many things , I´m just missing the concept  :~
Gear: Arduino- Uno,Due,Ethernet,  OLS, Buspirate, J-Link, TDS1002, Rigol DG1022

johnwasser

More brackets!  You need a set for each struct or array:

    You need brackets for the structure AnalogSensors.
        Within that you need brackets for the array CalPar.
            Within that you need brackets for each of the four CalibParams.
    THEN you put a value for SurfTemp.

Code: [Select]

struct AnalogSensors {
   CalibParam CalPar[4] ;     // E2P array of structures ex: an.CalPar.b
   int  SurfTemp;
   // ... snip
   int  BarPres;
   long avgarray[4];
} an =
{ // AnalogSensors
  { //CalPar array
    {0.0 , 5000.0/1024.0 , 0.0 } ,  // CalibParam CalPar[0]
    {0.0 , 5000.0/1024.0 , 0.0 } ,  // CalibParam CalPar[1]
    {0.0 , 1.0 , 0.0 },                 // CalibParam CalPar[2]
    {0.0 , 1.0 , 0.0 }                  // CalibParam CalPar[3]
  },
  999 // SurfTemp
};

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

astrofrostbyte

Gear: Arduino- Uno,Due,Ethernet,  OLS, Buspirate, J-Link, TDS1002, Rigol DG1022

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy