无符号与符号数为指标 [英] Unsigned versus signed numbers as indexes

查看:197
本文介绍了无符号与符号数为指标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请告诉我,使用符号数为指标的净道理呢?

Whats the rationale for using signed numbers as indexes in .Net?

在Python中,你可以从指数的阵列发送负数的结束,但这不是在.NET中的情况。 这是不容易的净增加这样的功能之后,它可以打破可能使用特殊规则等code(是的,一个坏主意,但我想它发生)的索引。

In Python, you can index from the end of an array by sending negative numbers, but this is not the case in .Net. It's not easy for .Net to add such a feature later as it could break other code perhaps using special rules (yeah, a bad idea, but I guess it happens) on indexing.

不,我曾经也需要数组索引的面积都超过2,147,483,647,但我真的不明白,为什么他们选择有符号数。

Not that I have ever have needed to index arrays over 2,147,483,647 in size, but I really cannot understand why they choose signed numbers.

这可能是因为这是比较正常的使用有符号数在code?

Can it be because it's more normal to use signed numbers in code?

编辑:我刚刚发现这些链接:

I just found these links:

无符号的迭代的危险在C / C ++

<一个href="http://www.digitalmars.com/pnews/read.php?server=news.digitalmars.com&group=digitalmars.D&artnum=111650"相对=nofollow>符号字长度和索引

EDIT2:好的,一对夫妇从线程马修•富兰琛贴其他原因:

Ok, a couple of other good reasons from the thread Matthew Flaschen posted:

  • 在历史的原因,因为它是一个类似C语言
  • 在互操作使用C

推荐答案

有关课程的简单性。你喜欢麻烦做算术大小无符号整型?

For simplicity of course. Do you like trouble doing size arithmetic with unsigned ints?

这篇关于无符号与符号数为指标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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