www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Type of Array.length?

reply Heinz <billgates microsoft.com> writes:
Hi,

I just want to know what type is the one returned by the .length property of an
array.

Thanks.
Jan 19 2007
next sibling parent Pragma <ericanderton yahoo.removeme.com> writes:
Heinz wrote:
 Hi,
 
 I just want to know what type is the one returned by the .length property of
an array.
 
 Thanks.
I think it's defined as an int (or possibly uint). If you're concerned about 32/64 bit compatibility then it's recommended that you use "size_t". http://www.digitalmars.com/d/portability.html "Use size_t as an alias for an unsigned integral type that can span the address space. Array indices should be of type size_t." -- - EricAnderton at yahoo
Jan 19 2007
prev sibling next sibling parent reply Alexander Panek <a.panek brainsware.org> writes:
Heinz wrote:
 Hi,
 
 I just want to know what type is the one returned by the .length property of
an array.
 
 Thanks.
Easiest way to achieve the array is either: typeof(array.length) len; or: auto len = array.length; You don't even have to really care for the type then, actually, and it stays platform independent, anyways.
Jan 19 2007
parent reply Heinz <billgates microsoft.com> writes:
Alexander Panek Wrote:

 Heinz wrote:
 Hi,
 
 I just want to know what type is the one returned by the .length property of
an array.
 
 Thanks.
Easiest way to achieve the array is either: typeof(array.length) len; or: auto len = array.length; You don't even have to really care for the type then, actually, and it stays platform independent, anyways.
Hi, thanks for your reply, i really like what yo did but i need this type to be fixed, not stored in a variable. Ok, now len is the same type as array.length, then what's the type of len? you know what i mean? The program knows the type but I need to know it too. Thanks man.
Jan 19 2007
parent reply Chris Nicholson-Sauls <ibisbasenji gmail.com> writes:
Heinz wrote:
 Alexander Panek Wrote:
 
 Heinz wrote:
 Hi,

 I just want to know what type is the one returned by the .length property of
an array.

 Thanks.
Easiest way to achieve the array is either: typeof(array.length) len; or: auto len = array.length; You don't even have to really care for the type then, actually, and it stays platform independent, anyways.
Hi, thanks for your reply, i really like what yo did but i need this type to be fixed, not stored in a variable. Ok, now len is the same type as array.length, then what's the type of len? you know what i mean? The program knows the type but I need to know it too. Thanks man.
size_t (Which is 'uint' on 32b systems, and 'ulong' on 64b.) -- Chris Nicholson-Sauls
Jan 19 2007
parent Heinz <billgates microsoft.com> writes:
Chris Nicholson-Sauls Wrote:

 Heinz wrote:
 Alexander Panek Wrote:
 
 Heinz wrote:
 Hi,

 I just want to know what type is the one returned by the .length property of
an array.

 Thanks.
Easiest way to achieve the array is either: typeof(array.length) len; or: auto len = array.length; You don't even have to really care for the type then, actually, and it stays platform independent, anyways.
Hi, thanks for your reply, i really like what yo did but i need this type to be fixed, not stored in a variable. Ok, now len is the same type as array.length, then what's the type of len? you know what i mean? The program knows the type but I need to know it too. Thanks man.
size_t (Which is 'uint' on 32b systems, and 'ulong' on 64b.) -- Chris Nicholson-Sauls
You're right. I wrote the array.length into a binary file and it uses only 4 bytes. Thanks.
Jan 20 2007
prev sibling parent reply Daniel Keep <daniel.keep+lists gmail.com> writes:
Heinz wrote:
 Hi,
 
 I just want to know what type is the one returned by the .length property of
an array.
 
 Thanks.
When in doubt, find out! import std.stdio; void main() { char[] foo; writefln("typeof(array.length) == %s", typeid(typeof(foo.length))); }
Jan 20 2007
parent Heinz <billgates microsoft.com> writes:
Daniel Keep Wrote:

 Heinz wrote:
 Hi,
 
 I just want to know what type is the one returned by the .length property of
an array.
 
 Thanks.
When in doubt, find out! import std.stdio; void main() { char[] foo; writefln("typeof(array.length) == %s", typeid(typeof(foo.length))); }
Cool man, thanks, this is what i need.
Jan 20 2007