How to initialize an array of struct?

dfx <[email protected]>
Newsgroups gmane.comp.hardware.avr.gcc
Organization dfx s.r.l.
Message-ID <[email protected]>
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

_______________________________________________
AVR-GCC-list mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/avr-gcc-list
dfx.vcf (text/x-vcard, 246 B)
begin:vcard
fn:Domenico Formenton
n:Formenton;Domenico
org:dfx
adr;dom:;;Via delle due Case, 12;APRILIA;LT;04011
email;internet:[email protected]
tel;work:06 92500019
tel;cell:333 7075929
x-mozilla-html:TRUE
url:www.dfx.it
version:2.1
end:vcard
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.