12.1.21. stddef.h. Altium TriCore
Reklama
Reklama
TASKING VX-toolset for TriCore User Guide
#define bool _Bool
#define true 1
#define false 0
#define __bool_true_false_are_defined 1
12.1.21. stddef.h
This header file defines the types for common use: ptrdiff_t size_t wchar_t
Signed integer type of the result of subtracting two pointers.
Unsigned integral type of the result of the sizeof
operator.
Integer type to represent character codes in large character sets.
Besides these types, the following macros are defined:
NULL offsetof(_type,
_member)
Expands to 0 (zero).
Expands to an integer constant expression with type size_t
that is the offset in bytes of
_member
within structure type
_type
.
12.1.22. stdint.h
See
Section 12.1.10, inttypes.h and stdint.h
12.1.23. stdio.h and wchar.h
Types
The header file stdio.h
contains functions for performing input and output. A number of functions also have a parallel wide character function or macro, defined in wchar.h
. The header file wchar.h
also includes stdio.h
.
In the C language, many I/O facilities are based on the concept of streams. The stdio.h
header file defines the data type
FILE
which holds the information about a stream. A
FILE
object is created with the function fopen
. The pointer to this object is used as an argument in many of the in this header file.
The
FILE
object can contain the following information:
• the current position within the stream
• pointers to any associated buffers
• indications of for read/write errors
• end of file indication
The header file also defines type fpos_t
as an unsigned long
.
708
Libraries
Macros stdio.h
NULL
BUFSIZ
EOF
WEOF
FOPEN_MAX
FILENAME_MAX
_IOFBF
_IOLBF
_IONBF
L_tmpnam
TMP_MAX
SEEK_CUR
SEEK_END
SEEK_SET stderr stdin stdout
Description
Expands to 0 (zero).
Size of the buffer used by the setbuf
/ setvbuf
function: 512
End of file indicator. Expands to -1.
End of file indicator. Expands to UINT_MAX (defined in limits.h
)
NOTE: WEOF need not to be a negative number as long as its value does not correspond to a member of the wide character set. (Defined in wchar.h
).
Number of files that can be opened simultaneously: 10
Maximum length of a filename: 100
Expand to an integer expression, suitable for use as argument to the setvbuf
function.
Size of the string used to hold temporary file names: 8 (tmpxxxxx)
Maximum number of unique temporary filenames that can be generated: 0x8000
Expand to an integer expression, suitable for use as the third argument to the fseek function.
Expressions of type "pointer to FILE" that point to the FILE objects associated with standard error, input and output streams.
File access stdio.h
fopen(name,mode) fclose(name) fflush(name)
Description
Opens a file for a given mode. Available modes are:
"r" read; open text file for reading
"w" write; create text file for writing; if the file already exists, its contents is discarded
"a" append; open existing text file or create new text file for writing at end of file
"r+" open text file for update; reading and writing
"w+" create text file for update; previous contents if any is discarded
"a+" append; open or create text file for update, writes at end of file
(FSS implementation)
Flushes the data stream and closes the specified file that was previously opened with fopen. (FSS implementation)
If stream is an output stream, any buffered but unwritten date is written.
Else, the effect is undefined. (FSS implementation)
709
TASKING VX-toolset for TriCore User Guide
stdio.h
freopen(name,mode,
stream)
Description
Similar to fopen, but rather than generating a new value of type FILE *, the existing value is associated with a new stream. (FSS implementation) setbuf(stream,buffer)
If buffer is NULL, buffering is turned off for the stream. Otherwise, setbuf is equivalent to:
(void) setvbuf(stream,buffer,_IOFBF,BUFSIZ)
.
setvbuf(stream,buffer,mode,
size)
Controls buffering for the stream; this function must be called before reading or writing. Mode can have the following values:
_IOFBF
causes full buffering
_IOLBF
causes line buffering of text files
_IONBF
causes no buffering.
If buffer is not NULL, it will be used as a buffer; otherwise a buffer will be allocated. size determines the buffer size.
Formatted input/output
The format
string of
printf
related functions can contain plain text mixed with conversion specifiers.
Each conversion specifier should be preceded by a '%' character. The conversion specifier should be built in order:
• Flags (in any order):
0
#
specifies left adjustment of the converted argument.
+ a number is always preceded with a sign character.
+
has higher precedence than space
.
space a negative number is preceded with a sign, positive numbers with a space.
specifies padding to the field width with zeros (only for numbers).
specifies an alternate output form. For o, the first digit will be zero. For x or X, "0x" and "0X" will be prefixed to the number. For e, E, f, g, G, the output always contains a decimal point, trailing zeros are not removed.
• A number specifying a minimum field width. The converted argument is printed in a field with at least the length specified here. If the converted argument has fewer characters than specified, it will be padded at the left side (or at the right when the flag '
-
' was specified) with spaces. Padding to numeric fields will be done with zeros when the flag '
0
' is also specified (only when padding left). Instead of a numeric value, also '
*
' may be specified, the value is then taken from the next argument, which is assumed to be of type int
.
• A period. This separates the minimum field width from the precision.
• A number specifying the maximum length of a string to be printed. Or the number of digits printed after the decimal point (only for floating-point conversions). Or the minimum number of digits to be printed for an integer conversion. Instead of a numeric value, also '
*
' may be specified, the value is then taken from the next argument, which is assumed to be of type int
.
• A length modifier 'h', 'hh', 'l', 'll', 'L', 'j', 'z' or 't'. 'h' indicates that the argument is to be treated as a short or unsigned short
. 'hh' indicates that the argument is to be treated as a char
or unsigned char
.
'l' should be used if the argument is a long
integer, 'll' for a long long
. 'L' indicates that the argument
710
Libraries
is a long double
. 'j' indicates a pointer to intmax_t
or uintmax_t
, 'z' indicates a pointer to size_t and 't' indicates a pointer to ptrdiff_t
.
Flags, length specifier, period, precision and length modifier are optional, the conversion character is not.
The conversion character must be one of the following, if a character following '%' is not in the list, the behavior is undefined: f e, E g, G a, A n u c s
Character Printed as
d, i o x, X int, signed decimal int, unsigned octal int, unsigned hexadecimal in lowercase or uppercase respectively p r, lr
R, lR
% int, unsigned decimal int, single character (converted to unsigned char) char *, the characters from the string are printed until a NULL character is found. When the given precision is met before, printing will also stop double double double double int *, the number of characters written so far is written into the argument. This should be a pointer to an integer in default memory. No value is printed.
pointer
__fract, __lfract
__accum, __laccum
No argument is converted, a '%' is printed.
printf conversion characters
All arguments to the
scanf
related functions should be pointers to variables (in default memory) of the type which is specified in the format string.
The format string can contain :
• Blanks or tabs, which are skipped.
• Normal characters (not '%'), which should be matched exactly in the input stream.
• Conversion specifications, starting with a '%' character.
Conversion specifications should be built as follows (in order) :
• A '*', meaning that no assignment is done for this field.
• A number specifying the maximum field width.
711
TASKING VX-toolset for TriCore User Guide
• The conversion characters d
, i
, n
, o
, u
and x
may be preceded by 'h' if the argument is a pointer to short
rather than int
, or by 'hh' if the argument is a pointer to char
, or by 'l' (letter ell) if the argument is a pointer to long
or by 'll' for a pointer to long long
, 'j' for a pointer to intmax_t
or uintmax_t
,
'z' for a pointer to size_t
or 't' for a pointer to ptrdiff_t
. The conversion characters e
, f
, and g may be preceded by 'l' if the argument is a pointer to double
rather than float
, and by 'L' for a pointer to a long double
.
• A conversion specifier. '*', maximum field width and length modifier are optional, the conversion character is not. The conversion character must be one of the following, if a character following '%' is not in the list, the behavior is undefined.
Length specifier and length modifier are optional, the conversion character is not. The conversion character must be one of the following, if a character following '%' is not in the list, the behavior is undefined.
f, F e, E g, G a, A n p r, lr
R, lR
[...] c s u x
Character Scanned as
i d o int, signed decimal.
int, the integer may be given octal (i.e. a leading 0 is entered) or hexadecimal (leading "0x" or "0X"), or just decimal.
int, unsigned octal.
int, unsigned decimal.
int, unsigned hexadecimal in lowercase or uppercase.
single character (converted to unsigned char).
char *, a string of non white space characters. The argument should point to an array of characters, large enough to hold the string and a terminating NULL character.
float float float float int *, the number of characters written so far is written into the argument. No scanning is done.
[^...]
% pointer; hexadecimal value which must be entered without 0x- prefix.
__fract, __lfract
__accum, __laccum
Matches a string of input characters from the set between the brackets. A NULL character is added to terminate the string. Specifying [ ]...] includes the ']' character in the set of scanning characters.
Matches a string of input characters not in the set between the brackets. A NULL character is added to terminate the string. Specifying [^]...] includes the ']' character in the set.
Literal '%', no assignment is done.
scanf conversion characters
712
Libraries
stdio.h
fscanf(stream,
format, ...) scanf(format,...) sscanf(*s, format,
...)
wchar.h
fwscanf(stream,
format, ...) wscanf(format, ...) swscanf(*s, format,
...)
Description
Performs a formatted read from the given stream.
Returns the number of items converted successfully. (FSS implementation)
Performs a formatted read from stdin
. Returns the number of items converted successfully. (FSS
implementation)
Performs a formatted read from the string s.
Returns the number of items converted successfully.
vfscanf(stream,
format, arg) vscanf(format, arg) vsscanf(*s, format,
arg) fprintf(stream,
format, ...) vfwscanf(stream,
format, arg)
Same as fscanf
/ fwscanf
, but extra arguments are given as variable argument list arg. (See
) vwscanf(format, arg)
Same as sscanf
/ swscanf
, but extra arguments are given as variable argument list arg. (See
) vswscanf(*s, format,
Same as scanf
/ wscanf
, but extra arguments
arg) are given as variable argument list arg. (See
) fwprintf(stream,
format, ...)
Performs a formatted write to the given stream.
Returns EOF/WEOF on error. (FSS
implementation)
printf(format, ...) sprintf(*s, format,
...) snprintf(*s, n,
format, ...) vfprintf(stream,
format, arg) vprintf(format, arg) vsprintf(*s, format,
arg) wprintf(format, ...)
Performs a formatted write to the stream stdout
.
Returns EOF/WEOF on error. (FSS
implementation)
swprintf(*s, n,
format, ...) vfwprintf(stream,
format, arg) vwprintf(format,
arg) vswprintf(*s,
format, arg)
Performs a formatted write to string s. Returns
EOF/WEOF on error.
Same as sprintf
, but n specifies the maximum number of characters (including the terminating null character) to be written.
Same as fprintf
/ fwprintf
, but extra arguments are given as variable argument list
arg. (See
Section 12.1.19, stdarg.h ) (FSS
implementation)
Same as printf
/ wprintf
, but extra arguments are given as variable argument list arg. (See
Section 12.1.19, stdarg.h ) (FSS implementation)
Same as sprintf
/ swprintf
, but extra arguments are given as variable argument list
arg. (See
713
TASKING VX-toolset for TriCore User Guide
Character input/output stdio.h
fgetc(stream) getc(stream) getchar(stdin) fgets(*s, n, stream) gets(*s, n, stdin) ungetc(c, stream) fputc(c, stream) putc(c, stream) putchar(c, stdout) fputs(*s, stream) puts(*s)
wchar.h
fgetwc(stream) getwc(stream) getwchar(stdin) fgetws(*s, n,
stream)
ungetwc(c, stream) fputwc(c, stream) putwc(c, stream) putwchar(c, stdout) fputws(*s, stream)
-
Description
Reads one character from stream. Returns the read character, or EOF/WEOF on error. (FSS
implementation)
Same as fgetc
/ fgetwc
except that is implemented as a macro.
(FSS implementation)
NOTE: Currently #defined as getchar()
/ getwchar()
because FILE I/O is not supported. Returns the read character, or
EOF/WEOF on error.
Reads one character from the stdin
stream.
Returns the character read or EOF/WEOF on error. Implemented as macro.
(FSS implementation)
Reads at most the next n-1 characters from the
stream into array s until a newline is found.
Returns s or NULL or EOF/WEOF on error. (FSS
implementation)
Reads at most the next n-1 characters from the stdin
stream into array s. A newline is ignored.
Returns s or NULL or EOF/WEOF on error. (FSS
implementation)
Pushes character c back onto the input stream.
Returns EOF/WEOF on error.
Put character c onto the given stream. Returns
EOF/WEOF on error. (FSS implementation)
Same as fpuc
/ fputwc
except that is implemented as a macro. (FSS implementation)
Put character c onto the stdout
stream. Returns
EOF/WEOF on error.
Implemented as macro. (FSS implementation)
Writes string s to the given stream. Returns
EOF/WEOF on error. (FSS implementation)
Writes string s to the stdout
stream. Returns
EOF/WEOF on error. (FSS implementation)
Direct input/output stdio.h
fread(ptr,size,nobj,stream)
Description
Reads nobj members of size bytes from the given stream into the array pointed to by ptr. Returns the number of elements successfully read. (FSS implementation)
714
Libraries
stdio.h
Description
fwrite(ptr,size,nobj,stream)
Writes nobj members of size bytes from to the array pointed to by ptr to the given stream. Returns the number of elements successfully written. (FSS implementation)
Random access stdio.h
fseek(stream, offset,
origin)
Description
Sets the position indicator for stream. (FSS implementation)
When repositioning a binary file, the new position origin is given by the following macros:
SEEK_SET 0
offset characters from the beginning of the file
SEEK_CUR 1
offset characters from the current position in the file
SEEK_END 2
offset characters from the end of the file ftell(stream) rewind(stream)
Returns the current file position for stream, or -1L on error.
(FSS implementation)
Sets the file position indicator for the stream to the beginning of the file. This function is equivalent to:
(void) fseek(stream,0L,SEEK_SET); clearerr(stream);
(FSS implementation) fgetpos(stream,pos)
Stores the current value of the file position indicator for stream in the object pointed to by pos. (FSS implementation) fsetpos(stream,pos)
Positions
stream
at the position recorded by fgetpos
in *pos. (FSS
implementation)
Operations on files stdio.h
Description
remove(file)
Removes the named file, so that a subsequent attempt to open it fails. Returns a non-zero value if not successful.
rename(old,new)
Changes the name of the file from old name to new name. Returns a non-zero value if not successful.
tmpfile() tmpnam(buffer)
Creates a temporary file of the mode " wb+
" that will be automatically removed when closed or when the program terminates normally. Returns a file
pointer.
Creates new file names that do not conflict with other file names currently in use.
The new file name is stored in a buffer which must have room for L_tmpnam characters. Returns a pointer to the temporary name. The file names are created in the current directory and all start with "tmp". At most TMP_MAX unique file names can be generated.
715
Preuzimanje
Reklama