C FAQ 15.2 [英] C FAQ 15.2

查看:53
本文介绍了C FAQ 15.2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问:在
printf中如何将%f用于浮点和双参数?它们不是不同的类型吗?


答:在可变长度参数

列表的可变长度部分中,''''默认参数促销''''适用:types char

和short int are提升为int,并将float提升为

double。 (这些是适用于没有原型范围的
函数调用的相同促销,也称为

`'old style''''函数调用;请参阅问题11.3 。)

因此,printf'的%f格式总是看到一个双倍。

(同样,%c总是看到一个int,%hd也是如此。)参见

问题12.9和12.13。


查看答案的第一句:在可变长度部分

a可变长度参数列表......


我很难理解它。第一句话

的含义究竟是什么?我的意思是为什么这个句子被包括在内?

非常清楚printf的参数是*总是*可变长度。

FAQ可以简单地说 printf().."


或者这意味着在这种情况下printf(),C语言不会将%c

转换为int:


printf(你输入:%c \ n,ch);


-
www.lispmachine.wordpress.com

我的电子邮件是@上面的博客。

谷歌群组被封锁。原因:过度垃圾邮件

Q: How can %f be used for both float and double arguments in
printf?Aren''t they different types?

A: In the variable-length part of a variable-length argument
list, the ''''default argument promotions'''' apply: types char
and short int are promoted to int, and float is promoted to
double. (These are the same promotions that apply to
function calls without a prototype in scope, also known as
``old style'''' function calls; see question 11.3.)
Therefore,printf''s %f format always sees a double.
(Similarly, %c always sees an int, as does %hd.) See also
questions 12.9 and 12.13.

Look at the first sentence of the Answer: "In the variable-length part of
a variable-length argument list..."

I have little trouble understanding it. What exactly is the meaning of
this first sentence. I mean why this sentence was included when it is
pretty much clear that arguments to printf are *always* variable-length.
FAQ could said simply "the arguments to printf().."

or does that mean in this case of printf(), C language will not convert %c
to an int:

printf("You entered: %c\n", ch);

--
www.lispmachine.wordpress.com
my email is @ the above blog.
Google Groups is Blocked. Reason: Excessive Spamming

推荐答案

arnuld写道:
arnuld wrote:

>

查看答案的第一句话:在

a可变长度参数列表的可变长度部分......


我很难理解它。第一句话

的含义究竟是什么?我的意思是为什么这个句子被包括在内?

非常清楚printf的参数是*总是*可变长度。

FAQ可以简单地说 printf().."
>
Look at the first sentence of the Answer: "In the variable-length part of
a variable-length argument list..."

I have little trouble understanding it. What exactly is the meaning of
this first sentence. I mean why this sentence was included when it is
pretty much clear that arguments to printf are *always* variable-length.
FAQ could said simply "the arguments to printf().."



printf的第一个参数是格式说明符,因此printf总是

至少有一个参数。


-

Ian Collins。

The first argument to printf is the format specifier, so printf always
has at least one argument.

--
Ian Collins.


2008年9月18日星期四17:12: 00 +1200,Ian Collins写道:
On Thu, 18 Sep 2008 17:12:00 +1200, Ian Collins wrote:

printf的第一个参数是格式说明符,所以printf总是

至少有一个参数。
The first argument to printf is the format specifier, so printf always
has at least one argument.



你误解了我的问题。我问*为什么* FAQ必须使用

句子,如......变长参数列表......当它绝对是

肯定printf总是有可变长度列表。

BTW,关于你的答案,printf的第一个参数是aformat

说明符,我认为,printf的第一个参数总是一个字符串文字

(或字符串常量或字符串或字符数组或任何你称之为
C中的
)可能或可能不包括*格式说明符。


-
www.lispmachine.wordpress.com

我的电子邮件是@上面的博客。

谷歌群组被阻止。原因:过度垃圾邮件

you misunderstood my question. I asked *Why* FAQ has to use
sentence like "...variable length argument list..." when it is definitely
sure that printf always has variable length list.
BTW, regarding your answer that first argument to printf is aformat
specifier, I think, first argument to printf is always a string literal
(or string constant or string or character array or whatever you call it
in C) which may or may not *include* format specifiers.


--
www.lispmachine.wordpress.com
my email is @ the above blog.
Google Groups is Blocked. Reason: Excessive Spamming


arnuld写道:
arnuld wrote:

> On Thu,2008年9月18日17:12:00 +1200,Ian Collins写道:
>On Thu, 18 Sep 2008 17:12:00 +1200, Ian Collins wrote:


> printf的第一个参数是格式说明符,所以printf总是至少有一个参数。
>The first argument to printf is the format specifier, so printf always
has at least one argument.



你误解了我的问题。我问*为什么* FAQ必须使用

句子,如......变长参数列表......什么时候肯定

确保printf总是有可变长度列表。


you misunderstood my question. I asked *Why* FAQ has to use
sentence like "...variable length argument list..." when it is definitely
sure that printf always has variable length list.



因为参数列表有两部分,固定部分和

可变长度部分。

Because there are two parts to the argument list, the fixed part and the
variable length part.


>

BTW,关于printf的第一个参数是格式化的答案

说明符,我认为,printf的第一个参数总是一个字符串文字

(或字符串常量或字符串或字符数组或任何你称之为
C中的
),可能包括也可能不包括* *格式说明符。
>
BTW, regarding your answer that first argument to printf is aformat
specifier, I think, first argument to printf is always a string literal
(or string constant or string or character array or whatever you call it
in C) which may or may not *include* format specifiers.



无论哪种方式,它仍然告诉函数有多少额外的参数



-

Ian Collins。

Either way, it still tells the function how many additional arguments
there are.

--
Ian Collins.


这篇关于C FAQ 15.2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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