avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avr-gcc-list] How to initialize an array of struct?


From: dfx
Subject: [avr-gcc-list] How to initialize an array of struct?
Date: Sat, 14 Dec 2013 17:57:26 +0100
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0

Hi,

After spending more than one day to create an array of struct I have
come to this code:

struct Lamp  {
  uint8_t highAddress [9] ;
  uint8_t lowAddress [9] ;
  uint8_t onoff ;
  uint8_t active ;
  uint8_t power;
  uint8_t brightness ;
  uint8_t temperatures ;
  uint8_t faultCount ;
} ;

struct Lamp lamps [10];


void init () {

  struct Lamp lamp0 = {" 0013A200 ", " 4094500D " , 0 , 1 , 0 , 0, 0 , 0} ;
  struct Lamp lamp1 = {" 0013A200 ", " 40B12530 " , 0 , 1 , 0 , 0, 0 , 0} ;
  struct Lamp lamp2 = {" 11111111 ", " 22222222 ", 0 , 0, 0 , 0, 0, 0 };
  struct Lamp lamp3 = {" 33333333 ", " 44444444 ", 0 , 0, 0 , 0, 0, 0 };
  struct Lamp lamp4 = {" 55555555 ", " 66666666 ", 0 , 0, 0 , 0, 0, 0 };
  struct Lamp lamp5 = {" 77777777 ", " 88888888 ", 0 , 0, 0, 0 , 0, 0 };
  struct Lamp lamp6 = {" 99999999 ", " 00000000 ", 0 , 0, 0, 0 , 0, 0 };
  struct Lamp lamp7 = {" AAAAAAAA ", " BBBBBBBB ", 0 , 0, 0, 0 , 0, 0 };
  struct Lamp lamp8 = {" CCCCCCCC ," " DDDDDDDD ", 0 , 0, 0, 0 , 0, 0 };
  struct Lamp lamp9 = {" EEEEEEEE ", " FFFFFFFF ", 0 , 0, 0, 0 , 0, 0 };

  lamps [0] = lamp0 ;
  lamps [1] = lamp1 ;
  lamps [2] = lamp2;
  lamps [3] = lamp3 ;
  lamps [4] = lamp4 ;
  lamps [5] = lamp5 ;
  lamps [6] = lamp6 ;
  lamps [7] = lamp7 ;
  lamps [8] = lamp8 ;
  lamps [9] = lamp9 ;
}

it compiles without errors ( and it may be that it works!) but it is
certainly wrong because it consumes twice the memory required (once for
the array [ 10] and another for 10 lamps).

The question is: how can I initialize the array without defining first
ten lamps individually ?

Thank you very much .

--
Domenico Formenton
Tel. 06 92731757
Fax. 178 2250847
Cell. 333 7075929



---
Questa e-mail è priva di virus e malware perché è attiva la protezione avast! 
Antivirus.
http://www.avast.com

Attachment: dfx.vcf
Description: Vcard


reply via email to

[Prev in Thread] Current Thread [Next in Thread]