преобразование входного формата (input format conversion)
Примечание (Note)
The 'a' assignment-allocation modifier
Originally, the GNU C library supported dynamic allocation for
string inputs (as a nonstandard extension) via the a
character.
(This feature is present at least as far back as glibc 2.0.)
Thus, one could write the following to have scanf
() allocate a
buffer for an input string, with a pointer to that buffer being
returned in *buf:
char *buf;
scanf("%as", &buf);
The use of the letter a
for this purpose was problematic, since a
is also specified by the ISO C standard as a synonym for f
(floating-point input). POSIX.1-2008 instead specifies the m
modifier for assignment allocation (as documented in DESCRIPTION,
above).
Note that the a
modifier is not available if the program is
compiled with gcc -std=c99 or gcc -D_ISOC99_SOURCE (unless
_GNU_SOURCE
is also specified), in which case the a
is
interpreted as a specifier for floating-point numbers (see
above).
Support for the m
modifier was added to glibc starting with
version 2.7, and new programs should use that modifier instead of
a
.
As well as being standardized by POSIX, the m
modifier has the
following further advantages over the use of a:
* It may also be applied to %c
conversion specifiers (e.g.,
%3mc
).
* It avoids ambiguity with respect to the %a
floating-point
conversion specifier (and is unaffected by gcc -std=c99 etc.).