Thursday, April 09, 2009

    Save PIC32 code (and maybe data) space by providing exit() in MPLAB C32

    The default exit() function, provided with the MPLAB C Compiler for PIC32 MCUs and called by the default startup code, does a lot of clean up that your application might not require. It does things like flushing I/O buffers. This could be completely unnecessary if your application never exits from your main function().

    You might want to consider providing your own exit() function to override the default implementation. This can save both code space and data space.

    If you're not using standard I/O, this stub implementation can save about 1 KB of code space and even some data space. Just add it to your project.
    void exit(int status)
    {
    while(1);
    }
    Even if you are using standard I/O, this stub could still save you a little space.

    No comments: