> From: John Porter [mailto:jdporter@min.net] > Sent: Tuesday, January 18, 2000 15:09 > To: Fun With Perl > Subject: Re: [FWP] That was productive... > > > * Larry Rosler (lr@hpl.hp.com) [000118 14:07]: > > > > Quite unlike Perl, the type of an array in C > > includes its size, which is statically compiled. > > > > So to find the number of elements in the array a, > > > > sizeof(a) / sizeof(a[0]) > > > > And the index of the last element is one less than that. > > Of course, this only works for static and automatic > variables, not for dynamic ones. > (Or am I wrong? And who cares? ;-) Well, I sort of, used to care. :-) There are no dynamic arrays in C, only dynamic blocks of memory. Strings are sequences of bytes terminated by a null byte, so strlen works. The length of 'arrays' (sequences of scalars) in allocated memory has to be specified by an external mechanism. As I said, the size of a C array is part of its type. Different sizes are different types. -- Larry Rosler Hewlett-Packard Laboratories http://www.hpl.hp.com/personal/Larry_Rosler/ lr@hpl.hp.com ==== Want to unsubscribe from Fun With Perl? Well, if you insist... ==== Send email to <fwp-request@technofile.org> with message _body_ ==== unsubscribe