08.04.2014 Views

cpik C compiler for PIC c -18 devices Version 0.7.1 - PiKdev, An IDE ...

cpik C compiler for PIC c -18 devices Version 0.7.1 - PiKdev, An IDE ...

cpik C compiler for PIC c -18 devices Version 0.7.1 - PiKdev, An IDE ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

9.3 Data structuration<br />

9.3.1 Array<br />

<strong>cpik</strong> currently supports arrays in any valid way.<br />

9.3.2 Struct and Union<br />

struct and union are supported since version 0.4, and this support is efficient. Unlike several other<br />

well known <strong>compiler</strong>s, <strong>cpik</strong> offers full support: structs can be passed to functions as parameters<br />

and can be returned by functions.<br />

structs are passed to function by value, as specified by the standard. <strong>An</strong>onymous structs are<br />

supported. structs are perfectly compatible with typedef. structs entities can be affected to<br />

other entities of same type.<br />

structs are guaranteed to be compact: as <strong>PIC</strong>-<strong>18</strong> architecture does not impose any alignment<br />

constraint, the size of a struct is the sum of the sizes of its members 8 .<br />

structs cannot be larger than 128 bytes 9 , but I suppose it is not a terrible limitation <strong>for</strong> a 8 bit<br />

microcontroller.<br />

Members of structs can be signed or unsigned bit fields. As stated by the standard, a bit field<br />

cannot cross an int boundary, so the size of a bit field can range from 1 to 8 bits. For example,<br />

in the following code<br />

struct XXX<br />

{<br />

unsigned a: 4 ,<br />

b: 4 ;<br />

} xxx ;<br />

struct YYY<br />

{<br />

unsigned a: 5 ,<br />

b: 4 ;<br />

} yyy ;<br />

the variable xxx is exactly 1 byte long, but the variable yyy is 2 bytes long because the second field<br />

is one bit too long to be inserted in the first byte. Please note that unsigned bit fields are more<br />

efficient than their signed couterpart because they don’t need to be sign extended when they are<br />

converted to int.<br />

Notice that bits are specified from low to high (so, in the above examples, a is the low nibble)<br />

9.4 Symbolic constants<br />

Symbolic integer constants can be defined with the traditionnal enum declarator.<br />

enum numbers { one=1, two, three } ;<br />

or<br />

typedef enum { peugeot=1, renault=2, citroen=4, other } cars ;<br />

8 However, this feature does no apply to structures composed of bit-fields, as explainded below.<br />

9 This feature is due to hardware limitation<br />

23

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

Saved successfully!

Ooh no, something went wrong!