C and C++ language interworking

This example shows a Thumb routine that carries out an interworking call to an ARM subroutine. The ARM subroutine makes an interworking call to printf() in the Thumb library.

Example 34. C and C++ language interworking

     *       thumbmain.c  *

     #include <stdio.h>

     extern void arm_function(void);

     int main(void)
          printf("Hello from Thumb\n");	
          printf("And goodbye from Thumb\n");	
          return (0);	

     *        armsub.c    *
     #include <stdio.h>

     void arm_function(void)
          printf("Hello and Goodbye from ARM\n");	

Show/hideBuilding the example

Follow these steps to build and link the modules:

  1. To compile the Thumb code for interworking, type:

    armcc --thumb -c --debug --apcs=/interwork thumbmain.c -o thumbmain.o
  2. To compile the ARM code for interworking, type:

    armcc -c --debug --apcs=/interwork armsub.c -o armsub.o
  3. To link the object files, type:

    armlink thumbmain.o armsub.o -o thumbtoarm.axf

    Alternatively, to view the size of the interworking veneers, type:

    armlink armsub.o thumbmain.o -o thumbtoarm.axf --info=veneers
  4. Run the image using a compatible debugger with an appropriate debug target.

Show/hideSee also

Copyright © 2010-2012 ARM. All rights reserved.ARM DUI 0471G