Using $Sub$$ to mix semihosted and nonsemihosted I/O functionality

You can use $Sub$$ to provide a mixture of semihosted and nonsemihosted functionality. For example, given an implementation of fputc() that writes directly to a UART, and a semihosted implementation of fputc(), you can provide both of these depending on the nature of the FILE * pointer passed into the function.

Example 1. Using $Sub$$ to mix semihosting and nonsemihosting I/O functionality

int $Super$$fputc(int c, FILE *fp);
int $Sub$$fputc(int c, FILE *fp)
{
    if (fp == (FILE *)MAGIC_NUM) // where MAGIC_NUM is a special value that
    {                            // is different to all normal FILE * pointer
                                 // values.
        write_to_UART(c);
        return c;
    }
    else
    {
        return $Super$$fputc(c, fp);
    }
}

Show/hideSee also

Copyright © 2010-2011 ARM. All rights reserved.ARM DUI 0475C
Non-ConfidentialID080411