%m格式说明符是什么意思? [英] What's the meaning of the %m formatting specifier?

查看:2611
本文介绍了%m格式说明符是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此代码的输出打印为成功".

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 %mdoes 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆