1.13 Target dependencies on low-level functions in the C and C++ libraries

Higher-level C and C++ library input/output functions are built upon lower-level functions. If you define your own versions of the lower-level functions, you can use the library versions of the higher-level functions directly.

The following table shows the dependencies of the higher-level functions on lower-level functions.

fgetc() uses __FILE, but fputc() uses __FILE and ferror().

Note:

  • You must provide definitions of __stdin and __stdout if you use any of their associated high-level functions. This applies even if your re-implementations of other functions, such as fgetc() and fputc(), do not reference any data stored in __stdin and __stdout.
  • When targeting the strict ANSI C standard, you must provide your own implementation of the __FILE structure. For example:
    struct __FILE { int handle; /* Add whatever you need here */ };
  • If you choose to re-implement fgetc(), fputc(), and __backspace(), be aware that fopen() and related functions use the ARM layout for the __FILE structure. You might also have to re-implement fopen() and related functions if you define your own version of __FILE.

Table key:

  1. __FILE, the file structure.

  2. __stdin, the standard input object of type __FILE.

  3. __stdout, the standard output object of type __FILE.

  4. fputc(), outputs a character to a file.

  5. ferror(), returns the error status accumulated during file I/O.

  6. fgetc(), gets a character from a file.

  7. fgetwc()

  8. fputwc()

  9. __backspace(), moves the file pointer to the previous character.

  10. __backspacewc().

Table 1-9 Input/output dependencies

High-level function Low-level object  
  1 2 3 4 5 6 7 8 9 10
fgets x - - - x x - - - -
fgetws x - - - - - x - - -
fprintf x - - x x - - - - -
fputs x - - x - - - - - -
fputws x - - - - - - x - -
fread x - - - - x - - - -
fscanf x - - - - x - - x -
fwprintf x - - - x - - x - -
fwrite x - - x - - - - - -
fwscanf x - - - - - x - - x
getchar x x - - - x - - - -
gets x x - - x x - - - -
getwchar x x - - - - x - - -
perror x - x x - - - - - -
printf x - x x x - - - - -
putchar x - x x - - - - - -
puts x - x x - - - - - -
putwchar x - x - - - - x - -
scanf x x - - - x - - x -
vfprintf x - - x x - - - - -
vfscanf x - - - - x - - x -
vfwprintf x - - - x - - x - -
vfwscanf x - - - - - x - - x
vprintf x - x x x - - - - -
vscanf x x - - - x - - x -
vwprintf x - x - x - - x - -
vwscanf x x - - - - x - - x
wprintf x - x - x - - x - -
wscanf x x - - - - x - - x
Non-ConfidentialPDF file icon PDF versionARM DUI0475M
Copyright © 2010-2016 ARM Limited or its affiliates. All rights reserved.