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 />

In the example above, the <strong>for</strong>mat string (my_<strong>for</strong>mat) is the second argument of the<br />

function my_print, <strong>and</strong> the arguments to check start with the third argument, so the<br />

correct parameters <strong>for</strong> the <strong>for</strong>mat attribute are 2 <strong>and</strong> 3.<br />

The <strong>for</strong>mat attribute allows you to identify your own functions that take <strong>for</strong>mat strings<br />

as arguments, so that the compiler can check the calls to these functions <strong>for</strong> errors. The<br />

compiler always checks <strong>for</strong>mats <strong>for</strong> the ANSI library functions printf, fprintf,<br />

sprintf, scanf, fscanf, sscanf, strftime, vprintf, vfprintf <strong>and</strong><br />

vsprintf, whenever such warnings are requested (using -W<strong>for</strong>mat), so there is no<br />

need to modify the header file stdio.h.<br />

<strong>for</strong>mat_arg (string-index)<br />

The <strong>for</strong>mat_arg attribute specifies that a function takes printf or scanf style<br />

arguments, modifies it (<strong>for</strong> example, to translate it into another language), <strong>and</strong> passes<br />

it to a printf or scanf style function. For example, consider the declaration:<br />

extern char *<br />

my_dgettext (char *my_domain, const char *my_<strong>for</strong>mat)<br />

__attribute__ ((<strong>for</strong>mat_arg (2)));<br />

This causes the compiler to check the arguments in calls to my_dgettext, whose<br />

result is passed to a printf, scanf or strftime type function <strong>for</strong> consistency with<br />

the printf style <strong>for</strong>mat string argument my_<strong>for</strong>mat.<br />

The parameter string-index specifies which argument is the <strong>for</strong>mat string<br />

argument (starting from 1).<br />

The <strong>for</strong>mat-arg attribute allows you to identify your own functions which modify<br />

<strong>for</strong>mat strings, so that the compiler can check the calls to printf, scanf or<br />

strftime function, whose oper<strong>and</strong>s are a call to one of your own functions.<br />

interrupt [ ( [ save(list) ] [, irq(irqid) ]<br />

[, altirq(altirqid)] [, preprologue(asm) ] ) ]<br />

Use this option to indicate that the specified function is an interrupt h<strong>and</strong>ler. The compiler<br />

will generate function prologue <strong>and</strong> epilogue sequences suitable <strong>for</strong> use in an interrupt<br />

h<strong>and</strong>ler when this attribute is present. The optional parameter save specifies a list<br />

of variables to be saved <strong>and</strong> restored in the function prologue <strong>and</strong> epilogue, respectively.<br />

The optional parameters irq <strong>and</strong> altirq specify interrupt vector table ID’s to be used.<br />

The optional parameter preprologue specifies assembly code that is to be emitted<br />

be<strong>for</strong>e the compiler-generated prologue code. See Chapter 8. “Interrupts” <strong>for</strong> a full<br />

description, including examples.<br />

When using the interrupt attribute, please specify either auto_psv or<br />

no_auto_psv. If none is specified a warning will be produced <strong>and</strong> auto_psv will be<br />

assumed.<br />

near<br />

The near attribute tells the compiler that the function can be called using a more<br />

efficient <strong>for</strong>m of the call instruction.<br />

no_instrument_function<br />

If the comm<strong>and</strong> line option -finstrument-function is given, profiling function calls<br />

will be generated at entry <strong>and</strong> exit of most user-compiled functions. Functions with this<br />

attribute will not be so instrumented.<br />

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

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

Saved successfully!

Ooh no, something went wrong!