11.07.2015 Views

MSP430 IAR C/C++ Compiler reference guide - Rice University

MSP430 IAR C/C++ Compiler reference guide - Rice University

MSP430 IAR C/C++ Compiler reference guide - Rice University

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Compiler</strong> extensionsDesignated initializers in structures and arraysAny initialization of either a structure (struct or union) or an array can have adesignation. A designation consists of one or more designators followed by aninitializer. A designator for a structure is specified as .elementname and for an array[constant index expression]. Using designated initializers is not supported in<strong>C++</strong>.ExamplesThe following definition shows a struct and its initialization using designators:struct{int i;int j;int k;int l;short array[10]} x = {.l.j = 6, /* initialize l and j to 6 */8, /* initialize k to 8 */{[7][3] = 2, /* initialize element 7 and 3 to 2 */5} /* initialize element 4 to 5 */.k = 4 /* reinitialize k to 4 */};Note that a designator specifies the destination element of the initialization. Note alsothat if one element is initialized more than once, it is the last initialization that will beused.To initialize an element in a union other than the first, do like this:union{int i;float f;}y = {.f = 5.0};To set the size of an array by initializing the last element, do like this:char array[] = {[10] = ‘a’};Part 2. <strong>Compiler</strong> <strong>reference</strong>185

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!