11.07.2015 Views

PicC 9.50 dsPIC Manual.pdf

PicC 9.50 dsPIC Manual.pdf

PicC 9.50 dsPIC Manual.pdf

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

C Language FeaturesLinking ProgramsAt link time the linker will report any mismatch of signatures. HI-TECH <strong>dsPIC</strong>C is only likelyto issue a mismatch error from the linker when the routine is either a precompiled object file or anassembly routine. Other function mismatches are reported by the code generator.TUT•RIALIt is sometimes necessary to write assembly language routines which are called from Cusing an extern declaration. Such assembly language functions should include a signaturewhich is compatible with the C prototype used to call them. The simplest method ofdetermining the correct signature for a function is to write a dummy C function with thesame prototype and compile it to assembly language using the DSPICC -S option. Forexample, suppose you have an assembly language routine called _widget which takestwo int arguments and returns a char value. The prototype used to call this functionfrom C would be:extern char widget(int, int);Where a call to _widget is made in the C code, the signature for a function with two intarguments and a char return value would be generated. In order to match the correctsignature the source code for widget needs to contain an assembler SIGNAT pseudo-opwhich defines the same signature value. To determine the correct value, you would writethe following code:char widget(int arg1, int arg2){}and compile it to assembler code usingDSPICC -S x.cThe resultant assembler code includes the following line:SIGNAT _widget,8249The SIGNAT pseudo-op tells the assembler to include a record in the .obj file whichassociates the value 8249 with symbol _widget. The value 8249 is the correct signaturefor a function with two int arguments and a char return value. If this line is copied intothe .as file where _widget is defined, it will associate the correct signature with thefunction and the linker will be able to check for correct argument passing. For example,if another .c file contains the declaration:extern char widget(long);then a different signature will be generated and the linker will report a signature mismatchwhich will alert you to the possible existence of incompatible calling conventions.63

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

Saved successfully!

Ooh no, something went wrong!