printfs.gml

来自「开放源码的编译器open watcom 1.6.0版的源代码」· GML 代码 · 共 464 行 · 第 1/2 页

GML
464
字号
.newtext Format Control String:
The format control string consists of
.us ordinary characters,
that are written exactly as they occur in the format string, and
.us conversion specifiers,
that cause argument values to be written as they are encountered
during the processing of the format string.
An ordinary character in the format string is any character, other
than a percent character (%), that is not part of a conversion
specifier.
A conversion specifier is a sequence of characters in the format
string that begins with a percent character (%) and is followed, in
sequence, by the following:
.begbull
.bull
zero or more
.us format control flags
that can modify the final effect of the format directive;
.bull
an optional decimal integer, or an asterisk character ('*'), that
specifies a
.us minimum field width
to be reserved for the formatted item;
.bull
an optional
.us precision
specification in the form of a period character (.),
followed by an optional decimal integer or an asterisk character (*);
.bull
an optional
.us type length
specification: one of "hh", "h", "l", "ll", "j", "z", "t", "L", "I64", "w"
.if &farfnc eq 0 .do begin
.ct
; and
.do end
.el .do begin
.ct ,
"N" or "W"; and
.do end
.bull
a character that specifies the type of conversion to be performed: one of
the characters "bcCdeEfFgGinopsSuxX".
.endbull
.np
The valid format control flags are:
.begnote $setptnt 3
.note "&minus."
the formatted item is left-justified within the field; normally, items
are right-justified
.note "+"
a signed, positive object will always start with a plus character
(+); normally, only negative items begin with a sign
.note "&sysrb"
a signed, positive object will always start with a space character; if
both "+" and "&sysrb." are specified, "+" overrides "&sysrb."
.note "#"
an alternate conversion form is used:
.begbull
.bull
for "b" (unsigned binary) and "o" (unsigned octal) conversions, the
precision is incremented, if necessary, so that the first digit is "0".
.bull
for "x" or "X" (unsigned hexadecimal) conversions, a non-zero value
is prepended with "0x" or "0X" respectively.
.bull
for "e", "E", "f", "F", "g" or "G" (any floating-point) conversions, the
result always contains a decimal-point character, even if no digits
follow it; normally, a decimal-point character appears in the result only
if there is a digit to follow it.
.bull
in addition to the preceding, for "g" or "G" conversions, trailing
zeros are not removed from the result.
.endbull
.endnote
.np
If no field width is specified, or if the value that is given is less
than the number of characters in the converted value (subject to any
precision value), a field of sufficient width to contain the converted
value is used.
If the converted value has fewer characters than are specified by the
field width, the value is padded on the left (or right, subject to the
left-justification flag) with spaces or zero characters ("0").
If the field width begins with "0" and no precision is specified, the
value is padded with zeros; otherwise the value is padded with spaces.
If the field width is "*", a value of type
.id int
from the argument list is used (before a precision argument or a
conversion argument) as the minimum field width.
A negative field width value is interpreted as a left-justification
flag, followed by a positive field width.
.np
As with the field width specifier, a precision specifier of "*" causes a
value of type
.id int
from the argument list to be used as the precision specifier.
If no precision value is given, a precision of 0 is used.
The precision value affects the following conversions:
.begbull
.bull
For "b", "d", "i", "o", "u", "x" and "X" (integer) conversions, the
precision specifies the minimum number of digits to appear.
.bull
For "e", "E", "f" and "F" (fixed-precision, floating-point) conversions, the
precision specifies the number of digits to appear after the
decimal-point character.
.bull
For "g" and "G" (variable-precision, floating-point) conversions, the
precision specifies the maximum number of significant digits to appear.
.bull
For "s" or "S" (string) conversions, the precision specifies the
maximum number of characters to appear.
.endbull
.np
A type length specifier affects the conversion as follows:
.begbull
.bull
"hh" causes a "b", "d", "i", "o", "u", "x" or "X" (integer) format
conversion to treat the argument as a
.id signed char
or
.id unsigned char
argument.
Note that, although the argument may have been promoted to an
.id int
as part of the function call, the value is converted to the smaller
type before it is formatted.
.bull
"hh" causes an "n" (converted length assignment) operation to assign the
converted length to an object of type
.id signed char.
.bull
"h" causes a "b", "d", "i", "o", "u", "x" or "X" (integer) format
conversion to treat the argument as a
.id short int
or
.id unsigned short int
argument.
Note that, although the argument may have been promoted to an
.id int
as part of the function call, the value is converted to the smaller
type before it is formatted.
.bull
.ix 'fixed-point'
"h" causes an "f" format conversion to interpret a
.id long
argument as a fixed-point number consisting of a 16-bit signed integer
part and a 16-bit unsigned fractional part.
The integer part is in the high 16 bits and the fractional part is in
the low 16 bits.
.millust begin
struct fixpt {
    unsigned short fraction; /* Intel architecture! */
      signed short integral;
};

struct fixpt foo1 =
  { 0x8000, 1234 }; /* represents 1234.5 */
struct fixpt foo2 =
  { 0x8000, -1 };   /* represents -0.5 (-1+.5) */
.millust end
.np
The value is formatted with the same rules as for floating-point values.
This is a &company extension.
.bull
"h" causes an "n" (converted length assignment) operation to assign the
converted length to an object of type
.id short int.
.bull
"h" causes an "s" operation to treat the argument string as an ASCII
character string composed of 8-bit characters.
.np
For
.kw printf
and related byte input/output functions, this specifier is redundant.
For
.kw wprintf
and related wide character input/output functions, this specifier is
required if the argument string is to be treated as an 8-bit ASCII
character string; otherwise it will be treated as a wide character
string.
.millust begin
printf(    "%s%d", "Num=", 12345 );
wprintf( L"%hs%d", "Num=", 12345 );
.millust end
.bull
"l" causes a "b", "d", "i", "o", "u", "x" or "X" (integer) conversion to
process a
.id long int
or
.id unsigned long int
argument.
.bull
"l" causes an "n" (converted length assignment) operation to assign the
converted length to an object of type
.id long int.
.bull
"l" or "w" cause an "s" operation to treat the argument string as a
wide character string (a string composed of characters of type
.kw wchar_t
.ct ).
.np
For
.kw printf
and related byte input/output functions, this specifier is required if
the argument string is to be treated as a wide character string;
otherwise it will be treated as an 8-bit ASCII character string.
For
.kw wprintf
and related wide character input/output functions, this specifier is
redundant.
.millust begin
printf(  "%ls%d", L"Num=", 12345 );
wprintf( L"%s%d", L"Num=", 12345 );
.millust end
.bull
.ix 'long long'
"ll" causes a "b", "d", "i", "o", "u", "x" or "X" (integer) conversion to
process a
.id long long
or
.id unsigned long long
argument (e.g., %lld).
.bull
"ll" causes an "n" (converted length assignment) operation to assign the
converted length to an object of type
.id long long int.
.bull
.ix 'intmax_t'
.ix 'uintmax_t'
"j" causes a "b", "d", "i", "o", "u", "x" or "X" (integer) conversion to
process an

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?