avatar
哈好啊,我是华佗# Joke - 肚皮舞运动
l*d
1
考虑这个函数
void foo(char c){
...
}
如果用户传递个大于127的值给c,比如 foo(128),在foo里c是溢出的,得到的值是-
128。如果用户在调用foo前判断传给c的值是不是大于127或小于-128很容易,有没有办
法在foo里检测传给c的值是溢出的呢,就是说,不依赖于函数的用户去检测溢出。
avatar
b*1
2
想到那儿买点树,但每次add to shopping cart,都是说Unable to process this
account's request。换电脑和浏览器也没用。
avatar
c*7
3
啦啦啦。。
avatar
l*8
4
应该没有办法。 foo()知道的就是char, 不知道之前有没有经过数据类型转换。

【在 l******d 的大作中提到】
: 考虑这个函数
: void foo(char c){
: ...
: }
: 如果用户传递个大于127的值给c,比如 foo(128),在foo里c是溢出的,得到的值是-
: 128。如果用户在调用foo前判断传给c的值是不是大于127或小于-128很容易,有没有办
: 法在foo里检测传给c的值是溢出的呢,就是说,不依赖于函数的用户去检测溢出。

avatar
b*1
5
nurcar的回复:
It is not a problem; it is intentional. Shipping has been suspended until
spring 2015 due to plants not surviving long times in cold trucks and/or
warehouses.
If you are in a warmer climate SE Coastal or S (east of the Rocky Mountains)
you can place an order earlier by calling 803 278 2336. Shipment dates will
depend on weather temperatures en route.
Our catalog ordering capability will be reinstated March 1 and we will begin
shipments on Mondays beginning April 6, 2015.
We appreciate your interest in Nurseries Caroliniana, Inc. and will be happy
to answer any other questions you may have.
Penny J Stoming
Wholesale Management
Nurseries Caroliniana, Inc
22 Stephens Estate
North Augusta, SC 29841
Phone 803 278 2336
avatar
h*e
6
像是在啃屁股。
avatar
l*d
7
用inline assembly,测试Overflow flag应该可以,但面试题应该不至于考那么细节吧

【在 l*********8 的大作中提到】
: 应该没有办法。 foo()知道的就是char, 不知道之前有没有经过数据类型转换。
avatar
h*f
8
Hmm...a char can hold 0x0-0xFF. 128=0x80...so no overflow..
I guess the question is to detect whether the input occupies more than 1
byte?
You probably could *if* it were foo(char*) or foo(char&).
avatar
f*n
9
"unsigned char" can hold 0 - 255
"signed char" can hold -128 to 127
"char" can be either signed or unsigned char, depending on the
implementation

【在 h*****f 的大作中提到】
: Hmm...a char can hold 0x0-0xFF. 128=0x80...so no overflow..
: I guess the question is to detect whether the input occupies more than 1
: byte?
: You probably could *if* it were foo(char*) or foo(char&).

avatar
h*f
10
right, remembered when I hit my bed..lol
avatar
i*r
11
You should not consider this case. Caller should ensure that. Plus, compiler
should warn on your input.
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。