www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Size_t on x86 is uint,on x64 is ulong,it's a good thing?

reply " FrankLike" <1150015857 qq.com> writes:
  Size_t  on x86 is uint,on x64 is ulong,it's a good thing?

   I don't think is ok.
   it  creates many convert  thing,such as length is ulong ,must 
cast to int or cast to uint. It will be waste of time ,I think.
Apr 17 2014
next sibling parent "John Colvin" <john.loughran.colvin gmail.com> writes:
On Thursday, 17 April 2014 at 16:36:29 UTC, FrankLike wrote:
  Size_t  on x86 is uint,on x64 is ulong,it's a good thing?

   I don't think is ok.
   it  creates many convert  thing,such as length is ulong ,must 
 cast to int or cast to uint. It will be waste of time ,I think.

It's the same in C and it reflects what the hardware is doing underneath with regard to memory addresses. That's the point of size_t. If it didn't change size then we'd all just use ulong or uint for all our array lengths etc.
Apr 17 2014
prev sibling next sibling parent Nick Sabalausky <SeeWebsiteToContactMe semitwist.com> writes:
On 4/17/2014 12:36 PM,  FrankLike wrote:
   Size_t  on x86 is uint,on x64 is ulong,it's a good thing?

    I don't think is ok.
    it  creates many convert  thing,such as length is ulong ,must cast to
 int or cast to uint. It will be waste of time ,I think.

If you want fixed-length, you use uint/ulong/etc. The whole point of size_t is for when you need the hardware's native data size.
Apr 17 2014
prev sibling next sibling parent "FrankLIKE" <1150015857 qq.com> writes:
On Thursday, 17 April 2014 at 16:46:15 UTC, John Colvin wrote:
 On Thursday, 17 April 2014 at 16:36:29 UTC, FrankLike wrote:
 Size_t  on x86 is uint,on x64 is ulong,it's a good thing?

  I don't think is ok.
  it  creates many convert  thing,such as length is ulong ,must 
 cast to int or cast to uint. It will be waste of time ,I think.

It's the same in C and it reflects what the hardware is doing underneath with regard to memory addresses. That's the point of size_t. If it didn't change size then we'd all just use ulong or uint for all our array lengths etc.

Thank you,I think 'use uint' is better than 'use ulong' . You know that 'point.x,point.y' is int ,on x64 ,no change, 'length' keeps the same to 'point.x,point.y' ,maybe a good thing. Frank.
Apr 17 2014
prev sibling next sibling parent "FrankLIKE" <1150015857 qq.com> writes:
 It's the same in C and it reflects what the hardware is doing 
 underneath with regard to memory addresses. That's the point of 
 size_t. If it didn't change size then we'd all just use ulong 
 or uint for all our array lengths etc.

In c#,add the new attribute 'longlength' on the new version,keep the ‘length' in the attributes,and the type 'int' or 'uint' that is ok for most of condition ,maybe a longlength is ok for a little condition. Thank you. Frank
Apr 17 2014
prev sibling parent "monarch_dodra" <monarchdodra gmail.com> writes:
On Friday, 18 April 2014 at 00:31:20 UTC, FrankLIKE wrote:
 Thank you,I think 'use uint' is better than 'use ulong' .
 You know that 'point.x,point.y' is int ,on x64 ,no change,
 'length' keeps the same to 'point.x,point.y' ,maybe a good 
 thing.

 Frank.

You are only supposed to use `size_t` (and `ptrdiff_t`) for things that represent pointer indexing, pointer offsets, or their genral abstractions (indexing a slice, getting the length of a range...). If you want to store "just a number", then select an integral type with pre-defined size.
Apr 17 2014