由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - c++ is too nasty
相关主题
一道有趣的面试题。stackexchange上超火 大家说说看法?贡献一道M的链表题
弱问个C++ 问题 (const_cast)刚一个interview问的好底层呀。。。
问道面试体(software)今天Amazon的phone interview
做硬件模拟器的职位有前途吗数组寻址速度问题?
C++ volatile请教两道面试题,请大家说说看法
小白问题:如何能短时间内提高C++能力?说说下午的面试经历。。。
最快的语言还是C/C++吗?位运算的复杂度是多少?
我觉得任何时候大家讨论的语言就两种,C++和最热的语言。发个高盛onsite的面经
相关话题的讨论汇总
话题: unsigned话题: int话题: signed话题: cpu话题: c++
进入JobHunting版参与讨论
1 (共1页)
s*****n
发帖数: 994
1
vector v;
v.push_back(1);
for (int i = -1; i < v.size(); i++){
....
}
The code will never run into the for loop..!
a****2
发帖数: 1458
2
why?

【在 s*****n 的大作中提到】
: vector v;
: v.push_back(1);
: for (int i = -1; i < v.size(); i++){
: ....
: }
: The code will never run into the for loop..!

t****t
发帖数: 6806
3
decent compiler will warn you if you enable enough warning options.

【在 s*****n 的大作中提到】
: vector v;
: v.push_back(1);
: for (int i = -1; i < v.size(); i++){
: ....
: }
: The code will never run into the for loop..!

g**u
发帖数: 504
4
I think size_type is unsigned int or unsigned long. Comparing int with
unsigned int will convert int to unsigned automatically, you can convert
unsigned to signed explicitly as the following
int length=(int)v.size();
for (int i = -1; i < length; i++){
...
}
But I cannot see why you want to use it in this way.

【在 s*****n 的大作中提到】
: vector v;
: v.push_back(1);
: for (int i = -1; i < v.size(); i++){
: ....
: }
: The code will never run into the for loop..!

s******3
发帖数: 7297
5
why don't you use iterator???
l***i
发帖数: 1309
6
C++ is user friendly, it is just picky in choosing friends :)
m********1
发帖数: 31
7
comparison between signed and unsigned integer expressions
g*********e
发帖数: 14401
8
if you use stl, why not use iterator
w****o
发帖数: 2260
9
Interesting articles to talk about size_t, which size_type in STL is defined
as
http://stackoverflow.com/questions/1119370/where-do-i-find-the-
http://eetimes.com/discussion/programming-pointers/4026076/Why-

【在 s*****n 的大作中提到】
: vector v;
: v.push_back(1);
: for (int i = -1; i < v.size(); i++){
: ....
: }
: The code will never run into the for loop..!

a********m
发帖数: 15480
10
这个是比较烦。不过还是有警告的,而且知道了也比较容易理解。

【在 s*****n 的大作中提到】
: vector v;
: v.push_back(1);
: for (int i = -1; i < v.size(); i++){
: ....
: }
: The code will never run into the for loop..!

相关主题
小白问题:如何能短时间内提高C++能力?贡献一道M的链表题
最快的语言还是C/C++吗?刚一个interview问的好底层呀。。。
我觉得任何时候大家讨论的语言就两种,C++和最热的语言。今天Amazon的phone interview
进入JobHunting版参与讨论
w****o
发帖数: 2260
11
就这个话题,想问点儿东西
到底 unsigned int在CPU里面是如何表示的?我觉得通常数据都是存在寄存器(
register)进行运算的。可是寄存器是不区分 signed 还是unsigned的吧?!
我觉得unsigned int这个只是编程语言和编译器弄出来的,不是CPU native support的
,到底编译器是如何区分singed和unsigned的?
是不是要写个代码,到gdb里看汇编来弄明白?!
谢谢!

【在 g**u 的大作中提到】
: I think size_type is unsigned int or unsigned long. Comparing int with
: unsigned int will convert int to unsigned automatically, you can convert
: unsigned to signed explicitly as the following
: int length=(int)v.size();
: for (int i = -1; i < length; i++){
: ...
: }
: But I cannot see why you want to use it in this way.

s*****n
发帖数: 994
12
Yes, you are correct. Always use "unsigned int i" when comparing with size()
function.
I am using index instead of iterator is because I have one more situation
which is not any of the vector elements to consider. This is the way to add
it in and save some duplicate lines.

【在 g**u 的大作中提到】
: I think size_type is unsigned int or unsigned long. Comparing int with
: unsigned int will convert int to unsigned automatically, you can convert
: unsigned to signed explicitly as the following
: int length=(int)v.size();
: for (int i = -1; i < length; i++){
: ...
: }
: But I cannot see why you want to use it in this way.

t****t
发帖数: 6806
13
quite the contrary, most CPU support unsigned and signed numbers. most
likely they share the binary representation, but instructions distinguish
them. for example, in x86 you have mul and imul for unsigned and signed
integer multiplication. for addition and subtraction, the operations are the
same anyway. but for comparison, CPU do check different flag.
so, the answer is no, most CPU natively support unsigned and signed integers.

【在 w****o 的大作中提到】
: 就这个话题,想问点儿东西
: 到底 unsigned int在CPU里面是如何表示的?我觉得通常数据都是存在寄存器(
: register)进行运算的。可是寄存器是不区分 signed 还是unsigned的吧?!
: 我觉得unsigned int这个只是编程语言和编译器弄出来的,不是CPU native support的
: ,到底编译器是如何区分singed和unsigned的?
: 是不是要写个代码,到gdb里看汇编来弄明白?!
: 谢谢!

m*********e
发帖数: 55
14
signed and unsigned compare应该有warning的

【在 s*****n 的大作中提到】
: vector v;
: v.push_back(1);
: for (int i = -1; i < v.size(); i++){
: ....
: }
: The code will never run into the for loop..!

c*********t
发帖数: 2921
15


【在 t****t 的大作中提到】
: quite the contrary, most CPU support unsigned and signed numbers. most
: likely they share the binary representation, but instructions distinguish
: them. for example, in x86 you have mul and imul for unsigned and signed
: integer multiplication. for addition and subtraction, the operations are the
: same anyway. but for comparison, CPU do check different flag.
: so, the answer is no, most CPU natively support unsigned and signed integers.

c*********t
发帖数: 2921
16
学习了。
是不是寄存器本身看不出有无符号?
是否按有符号数操作是由指令决定的?
一个signed和一个unsigned 比较的时候,用的指令同两个signed数作比较时用的指令
相同吗?

【在 t****t 的大作中提到】
: quite the contrary, most CPU support unsigned and signed numbers. most
: likely they share the binary representation, but instructions distinguish
: them. for example, in x86 you have mul and imul for unsigned and signed
: integer multiplication. for addition and subtraction, the operations are the
: same anyway. but for comparison, CPU do check different flag.
: so, the answer is no, most CPU natively support unsigned and signed integers.

y***d
发帖数: 2330
17
C/C++ 把各种 size 搞成 unsigned 类型,现在看来这实在是非常脑残的事情;
好处或许是个别程序可以管理更大一点空间,
而坏处就是所有程序都要操心类型转换;那一堆 signed-unsigned 的警告,本质上是
没有意义的事情,却每个人都要花精力在这个上面。

【在 s*****n 的大作中提到】
: vector v;
: v.push_back(1);
: for (int i = -1; i < v.size(); i++){
: ....
: }
: The code will never run into the for loop..!

y***d
发帖数: 2330
18
http://eetimes.com/discussion/programming-pointers/4026076/Why-
"Using unsigned int instead of int as the type of the third parameter lets
memcpy copy larger objects, at no additional cost."
机器是没有什么 cost,可是人力的额外消耗却是无尽的

defined

【在 w****o 的大作中提到】
: Interesting articles to talk about size_t, which size_type in STL is defined
: as
: http://stackoverflow.com/questions/1119370/where-do-i-find-the-
: http://eetimes.com/discussion/programming-pointers/4026076/Why-

1 (共1页)
进入JobHunting版参与讨论
相关主题
发个高盛onsite的面经C++ volatile请教
问以前编过多少行代码有什么用小白问题:如何能短时间内提高C++能力?
Linux context switch 高通 面试题。??最快的语言还是C/C++吗?
BB 一个电面题我觉得任何时候大家讨论的语言就两种,C++和最热的语言。
一道有趣的面试题。stackexchange上超火 大家说说看法?贡献一道M的链表题
弱问个C++ 问题 (const_cast)刚一个interview问的好底层呀。。。
问道面试体(software)今天Amazon的phone interview
做硬件模拟器的职位有前途吗数组寻址速度问题?
相关话题的讨论汇总
话题: unsigned话题: int话题: signed话题: cpu话题: c++