7.3.3 Declaring and initializing global Variables
The ANSI library functions reference the global variables listed in Table 7.3.3.1. These variables have been
defined in the libstdio.a library. Include "\include\libstdio.h" in the C source program and call the
_init_lib() function to initialize the variables before calling a library function.
For how to initialize the ANSI library using libstdio.a, refer to the sample file "\gnu17\sample\
S1C17common\simulator\simulatedIO".
global variable
FILE _iob[FOPEN_MAX +1];
FOPEN_MAX=3, defined in stdio.h
File structure data for standard
input/output streams
FILE *stdin;
Pointer to standard input/output file
structure data _iob[0]
FILE *stdout;
Pointer to standard input/output file
structure data _iob[1]
FILE *stderr;
Pointer to standard input/output file
structure data iob[2]
int errno;
Variable to store error number
unsigned int seed;
Variable to store seed of random
number
time_t gm_sec;
Elapsed time of timer function in
seconds from 0:00:00 on January 1,
1970
Among the global variables referenced by the ANSI library functions, those that are used by each function (mal-
loc, calloc, realloc, and free) are initialized using the initialization function shown below. This function is
defined in stdlib.h.
int ansi_InitMalloc(unsigned long START_ADDRESS, unsigned long END_ADDRESS);
For the START_ADDRESS and END_ADDRESS, set the start and end addresses of the memory used, respectively.
These addresses are adjusted to the 4-byte boundaries within the function.
The following global variables are initialized. These variables are defined in stdlib.h.
unsigned char *ansi_ucStartAlloc;
unsigned char *ansi_ucEndAlloc;
unsigned char *ansi_ucNxtAlcP;
unsigned char *ansi_ucTblPtr;
unsigned long ansi_ulRow;
Each time storage is reserved for a heap area, eight-byte heap area management data is written from the ending
address (ansi_ucEndAlloc) toward the beginning address. Be careful to avoid rewriting areas specified as heap
areas by the ansi_InitMalloc() function by a stack pointer, etc.
* The libstdio.a library does not contain the ansi_InitMalloc() function. Be aware that it must be
called from the user routine before calling malloc() or a similar function. (A heap area cannot be allocated if
the ansi_InitMalloc() function is not called.)
S5U1C17001C ManUal
(C COMPilEr PaCkagE fOr S1C17 faMily) (Ver. 1.5.0)
Table 7.3.3.1 Global variables required of declaration
initial setting
_iob[N]._flg = _UGETN;
_iob[N]._buf = 0;
= N;
_iob[N]._fd
(N=0–2)
_iob[0]: Input data for stdin
_iob[1]: Output data for stdout
_iob[2]: Output data for stderr
stdin = &_iob[0];
stdout = &_iob[1];
stderr = &_iob[2];
errno = 0;
seed = 1;
gm_sec = -1;
Pointer to indicate the start address of the heap area
Pointer to indicate the end address of the heap area
Address pointer to indicate the beginning of the next new area mapped
Address pointer to indicate the beginning of the next management area
mapped
Line pointer to indicate the next management area mapped
EPSOn
related header file/function
stdio.h, smcvals.h
fgets, fread, fscanf, getc, getchar, gets, scanf,
ungetc, perror, fprintf, fputs, fwrite, printf,
putc, putchar, puts, vfprintf, vprintf
stdio.h
fgets, fread, fscanf, getc, getchar, gets, scanf,
ungetc
stdio.h
fprintf, fputs, fwrite, printf, putc, putchar,
puts, vfprintf, vprintf
stdio.h
fprintf, fputs, fwrite, printf, perror, putc,
putchar, puts, vfprintf, vprintf
errno.h
perror, fprintf, printf, sprintf, vprintf,
vfprintf, fscanf, scanf, sscanf
atof, atoi, calloc, div, ldiv, malloc, realloc, str-
tod, strtol, strtoul
acos, asin, atan2, ceil, cos, cosh, exp, fabs, floor,
fmod, frexp, ldexp, log, log10, modf, pow, sin, sinh,
sqrt, tan
stdlib.h
rand, srand
time.h
time
7 liBrary
7
Library
7-15
Need help?
Do you have a question about the S5U1C17001C and is the answer not in the manual?