Thread overview
Type of Array.length?
Jan 19, 2007
Heinz
Jan 19, 2007
Pragma
Jan 19, 2007
Alexander Panek
Jan 20, 2007
Heinz
Jan 20, 2007
Heinz
Jan 20, 2007
Daniel Keep
Jan 20, 2007
Heinz
January 19, 2007
Hi,

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

Thanks.
January 19, 2007
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
January 19, 2007
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.
January 20, 2007
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.

January 20, 2007
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
January 20, 2007
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)));
}
January 20, 2007
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.

January 20, 2007
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.