07.04.2013 Views

MPLAB C Compiler for PIC24 MCUs and dsPIC DSCs ... - Microchip

MPLAB C Compiler for PIC24 MCUs and dsPIC DSCs ... - Microchip

MPLAB C Compiler for PIC24 MCUs and dsPIC DSCs ... - Microchip

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.

Differences Between 16-Bit Device C <strong>and</strong> ANSI C<br />

2.3.5 Complex Numbers<br />

The compiler supports complex data types. You can declare both complex integer<br />

types <strong>and</strong> complex floating types, using the keyword __complex__.<br />

For example, __complex__ float x; declares x as a variable whose real part <strong>and</strong><br />

imaginary part are both of type float. __complex__ short int y; declares y to<br />

have real <strong>and</strong> imaginary parts of type short int.<br />

To write a constant with a complex data type, use the suffix ‘i’ or ‘j’ (either one; they<br />

are equivalent). For example, 2.5fi has type __complex__ float <strong>and</strong> 3i has type<br />

__complex__ int. Such a constant is a purely imaginary value, but you can <strong>for</strong>m<br />

any complex value you like by adding one to a real constant.<br />

To extract the real part of a complex-valued expression exp, write __real__ exp.<br />

Similarly, use __imag__ to extract the imaginary part. For example;<br />

__complex__ float z;<br />

float r;<br />

float i;<br />

r = __real__ z;<br />

i = __imag__ z;<br />

The operator ‘~’ per<strong>for</strong>ms complex conjugation when used on a value with a complex<br />

type.<br />

The compiler can allocate complex automatic variables in a noncontiguous fashion; it’s<br />

even possible <strong>for</strong> the real part to be in a register while the imaginary part is on the stack<br />

(or vice-versa). The debugging in<strong>for</strong>mation <strong>for</strong>mat has no way to represent noncontiguous<br />

allocations like these, so the compiler describes noncontiguous complex<br />

variables as two separate variables of noncomplex type. If the variable’s actual name<br />

is foo, the two fictitious variables are named foo$real <strong>and</strong> foo$imag.<br />

2.3.6 Double-Word Integers<br />

The compiler supports data types <strong>for</strong> integers that are twice as long as long int.<br />

Simply write long long int <strong>for</strong> a signed integer, or unsigned long long int<br />

<strong>for</strong> an unsigned integer. To make an integer constant of type long long int, add the<br />

suffix LL to the integer. To make an integer constant of type unsigned long long<br />

int, add the suffix ULL to the integer.<br />

You can use these types in arithmetic like any other integer types. Addition, subtraction<br />

<strong>and</strong> bitwise boolean operations on these types are open-coded, but division <strong>and</strong> shifts<br />

are not open-coded. The operations that are not open-coded use special library<br />

routines that come with the compiler.<br />

2.3.7 Referring to a Type with typeof<br />

Another way to refer to the type of an expression is with the typeof keyword. The<br />

syntax <strong>for</strong> using this keyword looks like sizeof, but the construct acts semantically like<br />

a type name defined with typedef.<br />

There are two ways of writing the argument to typeof: with an expression or with a<br />

type. Here is an example with an expression:<br />

typeof (x[0](1))<br />

This assumes that x is an array of functions; the type described is that of the values of<br />

the functions.<br />

Here is an example with a typename as the argument:<br />

typeof (int *)<br />

© 2008 <strong>Microchip</strong> Technology Inc. DS51284H-page 29

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

Saved successfully!

Ooh no, something went wrong!