5

I was wondering why do we use integers to get addresses in memory while memory addresses can only be positive? Why don't we use unsigned integers?

For example:
in C#, why do we have IntPtr, why not UIntPtr?
Arrays also have a limitation of Int32.Max. Still, why not unsigned since index can only be >= 0?
Also, in C++, a lot of codes assign a pointer address to ints, and not uints, is there a reason behind it? Is it bad practice?

Thank you!

user3439065
  • 840
  • 5
  • 8
  • see here http://stackoverflow.com/questions/6301/why-is-array-length-an-int-and-not-an-uint – thumbmunkeys Jul 05 '14 at 09:07
  • @MatsPetersson I considered closing too, but decided against it because none of the reasons in the answers to that other question apply to C++, and the OP asks about both C# and C++. Are you sure closing is appropriate at this point? (I understand it's a judgement call, if you still feel it's appropriate I won't re-open.) –  Jul 05 '14 at 09:19
  • In C# there is [UIntPtr](http://msdn.microsoft.com/en-us/library/system.uintptr%28v=vs.110%29.aspx). – l'L'l Jul 05 '14 at 09:21
  • I'm not sure that there is THAT much to answer... Using signed or unsigned makes little difference when dealing with pointers (unless you use the integer type for comparison, AND have a system where pointers cross the 31st or 63rd bit...) – Mats Petersson Jul 05 '14 at 09:22
  • Then why do we never use it? All the .NET Framework implementations are done using IntPtr... About closing the post, I do understand there is a duplicate; however not all the answers are on the other post. Thank you :) – user3439065 Jul 05 '14 at 09:25

0 Answers0