整数促销 [英] integer promotions

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

问题描述

大家好,


假设x被声明为char x,函数f()带有原型void

f(char y)。


假设f()在代码中的某处被调用并且:


1.提供了f()的原型,然后是一个x的字节副本传递给

f()(unix / intel平台)。

2.未提供原型,然后是一个四字节的int,其中包含

的x值传递给f()(unix / intel平台)。

3.如果f()是一个可变函数,则为4字节int,包含

的值x,传递给f()unix / intel平台)。


对吗?


TIA

Hi all,

Assume x is declared as char x, and a function f( ) with prototype void
f(char y).

Assume f( ) is invoked somewhere in the code and:

1. The f( )''s prototype is provided, then an one-byte copy of x is passed to
f( ) (unix/intel platform).
2. The prototype is not provided, then a four-byte int, which contains the
value of x, is passed to f( ) (unix/intel platform).
3. If f( ) was a variadic function instead, a four-byte int, which contains
the value of x, is passed to f( ) unix/intel platform).

Right?

TIA

推荐答案

" jimjim" <是ne ***** @ blueyonder.co.uk>写道:
"jimjim" <ne*****@blueyonder.co.uk> wrote:
假设x被声明为char x,而函数f()则带有原型void
f(char y)。
假设f()在某处被调用代码和:
1。提供了f()的原型,然后将x的一个字节副本传递给
f()(unix / intel平台)。
2。未提供原型,然后将包含x的值的四字节int传递给f()(unix / intel平台)。


是的,但只有在假设char变量存储在

单字节(定义字节?)并且sizeof(int)是4.

在unix / intel平台中最有可能是真的,但不一定如此。

(我目前正在研究在TI 2812 DSP上运行的代码。有
没有字节(八位字节)寻址,char和int类型都是16位)

3.如果f()是一个可变函数而是一个四字节int,其中包含x的值,传递给f()unix / intel平台)。
Assume x is declared as char x, and a function f( ) with prototype void
f(char y).
Assume f( ) is invoked somewhere in the code and:
1. The f( )''s prototype is provided, then an one-byte copy of x is passed to
f( ) (unix/intel platform).
2. The prototype is not provided, then a four-byte int, which contains the
value of x, is passed to f( ) (unix/intel platform).
Yes, but only if you are assuming that a char variable is stored in a
single byte (define byte?) and the sizeof(int) is 4.
Most likely true in a "unix/intel platform", but not necessarily so.
( I am currently working on code running on a TI 2812 DSP. There is
no byte (octet) addressing, both char and int types are 16 bits )
3. If f( ) was a variadic function instead, a four-byte int, which contains
the value of x, is passed to f( ) unix/intel platform).




不适用于此f()。可变函数必须至少有一个常规函数。参数。


Roberto Waltman


[请回复小组,]

[返回地址无效。 ]



Not applicable to this f(). A variadic function must have at least
one "regular" parameter.

Roberto Waltman

[ Please reply to the group, ]
[ return address is invalid. ]


文章< 6q ******************* @ text.news.blueyonder.co.u K> " jimjim" <是ne ***** @ blueyonder.co.uk>写道:

....
In article <6q*******************@text.news.blueyonder.co.u k> "jimjim" <ne*****@blueyonder.co.uk> writes:
....
3.如果f()是一个可变函数而是一个四字节的int,其中包含
x的值,传递到f()unix / intel平台)。
3. If f( ) was a variadic function instead, a four-byte int, which contains
the value of x, is passed to f( ) unix/intel platform).




不,请看另一个帖子中的文章。

-

dik t。冬天,cwi,kruislaan 413,1098 sj amsterdam,nederland,+ 31205924131

home:bovenover 215,1025 jn amsterdam,nederland; http://www.cwi.nl/~dik/


2005年9月13日星期二16:49:06 GMT,jimjim < ne ***** @ blueyonder.co.uk>

在comp.lang.c中写道:
On Tue, 13 Sep 2005 16:49:06 GMT, "jimjim" <ne*****@blueyonder.co.uk>
wrote in comp.lang.c:
大家好,

假设x被声明为char x,函数f()带有原型void
f(char y)。

假设f()在代码中的某处被调用:

1.提供了f()的原型,然后将x的一个字节副本传递给
f()(unix / intel平台)。


不,''x'的值作为char传递,这是一个字节,用C表示定义
(但可能有多个8位)。

2.未提供原型,然后将包含x的值的四字节int传递给f()(unix / intel平台) )。


如果你在没有原型范围的情况下调用函数,那么你在默认情况下调用它的数量和

类型的参数

促销必须与

函数定义为接受的参数的数量和类型完全匹配。如果不是这样,那么你就会产生未定义的行为,所以在这里发生的事情并不重要因为

它的游戏结束了,你输了。 />

因此,如果你有一个函数接受float,plain,
signed,或unsigned char,或者signed或unsigned short的参数,你可以''在没有范围原型的情况下调用

。嗯,你可以,但是我们在这里不会谈论这个,因为我们和C语言都不知道或关心什么是b
。它可能会从您的盒子中擦除UNIX操作系统并安装Windows

95,我们所关心的一切。

3.如果f()是一个可变函数,则为四 - byte int,包含
x的值,传递给f()unix / intel platform)。


如果f()是一个可变函数,当你调用它时,必须有范围内的原型

,或者你回到未定义的行为而且我们不需要b $ b护理。如果存在可变参数函数,则将char传递给...中参数的一个/ b $ b。部分,然后char的值是

提升为int而int是按值传递的。那个int是

sizeof(int)字节,有时是一个字节,但通常更多。


但它始终是sizeof(int)字节,那个无论

平台是什么都是如此。如果平台对你的问题很重要,那么在这里问你是不是


对吗?
Hi all,

Assume x is declared as char x, and a function f( ) with prototype void
f(char y).

Assume f( ) is invoked somewhere in the code and:

1. The f( )''s prototype is provided, then an one-byte copy of x is passed to
f( ) (unix/intel platform).
No, the value of ''x'' is passed as a char, which is one byte by
definition in C (but may have more than 8-bits).
2. The prototype is not provided, then a four-byte int, which contains the
value of x, is passed to f( ) (unix/intel platform).
If you call a function without a prototype in scope, the number and
types of arguments that you call it with, after the default
promotions, must exactly match the number and types of arguments the
function is defined to accept. If this is not true, you produce
undefined behavior, so it doesn''t matter here what happens because
it''s game over, you lose.

So if you have a function that accepts a parameter of a float, plain,
signed, or unsigned char, or signed or unsigned short, you can''t call
it without a prototype in scope. Well you can, but we don''t talk
about it here, because neither we nor the C language know or care what
happens. It might wipe the UNIX OS off your box and install Windows
95, for all we care.
3. If f( ) was a variadic function instead, a four-byte int, which contains
the value of x, is passed to f( ) unix/intel platform).
If f() was a variadic function, there must be a prototype in scope
when you call it, or you''re back to undefined behavior and we don''t
care. If there is a variadic function, and the char is passed to one
of the arguments in the "..." portion, then the value of the char is
promoted to an int and the int is passed by value. That int is
sizeof(int) bytes, which is sometimes one byte but usually more.

But it is always sizeof(int) bytes, and that is true whatever the
platform is. If the platform is important to your question, you are
wrong to ask it here.
Right?




好吧,不,不完全。


如果您不知道平台上有什么sizeof(int),请编译并运行以下
运行以下内容程序:


#include< stdio.h>

int main(无效)

{

printf(" sizeof(int)is%d \ n",(int)sizeof(int));

返回0;

}


-

Jack Klein

主页: http://JK-Technology.Com

常见问题解答

comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html

comp.lang.c ++ http://www.parashift.com/c++-faq-lite/

alt.comp.lang.learn.c-c ++
http://www.contrib。 andrew.cmu.edu/~a...FAQ-acllc.html



Well, no, not completely.

If you don''t know what sizeof(int) is on your platform, compile and
run the following program:

#include <stdio.h>
int main(void)
{
printf("sizeof(int) is %d\n", (int)sizeof(int));
return 0;
}

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html


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

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