%m格式说明符是什么意思? [英] What's the meaning of the %m formatting specifier?
问题描述
此代码的输出打印为成功".
printf("%m\n");
m
转换说明符不是C,而是对printf
的GNU扩展:
来自GNU文档:
http://www.gnu.org/软件/libc/manual/html_node/Other-Output-Conversions.html
%m"转换会打印与errno中的错误代码相对应的字符串.请参阅错误消息.因此:
fprintf (stderr, "can't open `%s': %m\n", filename);
等效于:
fprintf (stderr, "can't open `%s': %s\n", filename, strerror (errno));
%m"转换是GNU C库扩展.
所以:
printf("%m\n", d);
等同于
printf("%s\n", strerror (errno), d);
等效于
printf("%s\n", strerror (errno));
请注意,%m
不需要参数.这里的printf("%m\n", d)
和printf("%s\n", strerror (errno), d)
具有比所需更多的参数:使用printf
时,如果有多余的尾随参数,则它们将被求值并忽略.
The output for this code printed out ‘Success’.
printf("%m\n");
m
conversion specifier is not C but is a GNU extension to printf
:
From GNU documentation:
http://www.gnu.org/software/libc/manual/html_node/Other-Output-Conversions.html
The ‘%m’ conversion prints the string corresponding to the error code in errno. See Error Messages. Thus:
fprintf (stderr, "can't open `%s': %m\n", filename);
is equivalent to:
fprintf (stderr, "can't open `%s': %s\n", filename, strerror (errno));
The ‘%m’ conversion is a GNU C Library extension.
So:
printf("%m\n", d);
is equivalent to
printf("%s\n", strerror (errno), d);
which is equivalent to
printf("%s\n", strerror (errno));
Note that %m
does not require an argument. Here printf("%m\n", d)
and printf("%s\n", strerror (errno), d)
have more arguments than required: with printf
if there are extra trailing arguments, they are just evaluated and ignored.
这篇关于%m格式说明符是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!