Velocity Reviews > how to measure size of an array

# how to measure size of an array

asit dhal
Guest
Posts: n/a

 02-14-2007
Can anyone tell how to measure the size of an array without use of
sizeof operator ?

Ben Pfaff
Guest
Posts: n/a

 02-14-2007
"asit dhal" <(E-Mail Removed)> writes:

> Can anyone tell how to measure the size of an array without use of
> sizeof operator ?

How about referring to one of the many threads in the last few
months that discuss this same lame question, instead of starting
--
int main(void){char p[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv wxyz.\
\n",*q="kl BIcNBFr.NKEzjwCIxNJC";int i=sizeof p/2;char *strchr();int putchar(\
);while(*q){i+=strchr(p,*q++)-p;if(i>=(int)sizeof p)i-=sizeof p-1;putchar(p[i]\
);}return 0;}

lovecreatesbea...@gmail.com
Guest
Posts: n/a

 02-14-2007
On Feb 14, 9:02 am, "asit dhal" <(E-Mail Removed)> wrote:
> Can anyone tell how to measure the size of an array without use of
> sizeof operator ?

The size information is given at declaration of an array. When an
array is passed into a function, the sizeof can't evaluate the size of
the array inside the function.

Jamie Boy
Guest
Posts: n/a

 02-14-2007
asit dhal:

> Can anyone tell how to measure the size of an array without use of
> sizeof operator ?

(char*)pover - (char*)p

--
~/JB\~

Keith Thompson
Guest
Posts: n/a

 02-14-2007
"asit dhal" <(E-Mail Removed)> writes:
> Can anyone tell how to measure the size of an array without use of
> sizeof operator ?

Use the sizeof operator. That's what it's for.

--
Keith Thompson (The_Other_Keith) http://www.velocityreviews.com/forums/(E-Mail Removed) <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.

Joe Wright
Guest
Posts: n/a

 02-14-2007
asit dhal wrote:
> Can anyone tell how to measure the size of an array without use of
> sizeof operator ?
>

No.

--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---

Richard Heathfield
Guest
Posts: n/a

 02-14-2007
(E-Mail Removed) said:

> On Feb 14, 9:02 am, "asit dhal" <(E-Mail Removed)> wrote:
>> Can anyone tell how to measure the size of an array without use of
>> sizeof operator ?

>
> The size information is given at declaration of an array. When an
> array is passed into a function, the sizeof can't evaluate the size of
> the array inside the function.

You don't pass an array to a function. You pass a pointer to that
array's first element.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.

Malcolm McLean
Guest
Posts: n/a

 02-14-2007

"Jamie Boy" <(E-Mail Removed)> wrote in message n
>> Can anyone tell how to measure the size of an array without use of
>> sizeof operator ?

>
>
> (char*)pover - (char*)p
>
>

Make that unsigned char *.
char * should be reserved for genuine character data, and can contain trap
representations. A highly unlikely but allowable implementation could even
crash your program if one of the pointers points to a trap representation.
> --
> ~/JB\~

Ben Pfaff
Guest
Posts: n/a

 02-14-2007
"Malcolm McLean" <(E-Mail Removed)> writes:

> "Jamie Boy" <(E-Mail Removed)> wrote in message n
>>> Can anyone tell how to measure the size of an array without use of
>>> sizeof operator ?

>> (char*)pover - (char*)p

> Make that unsigned char *.
> char * should be reserved for genuine character data, and can contain trap
> representations. A highly unlikely but allowable implementation could even
> crash your program if one of the pointers points to a trap representation.

I don't believe this. Can you cite chapter & verse on that?
--
int main(void){char p[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv wxyz.\
\n",*q="kl BIcNBFr.NKEzjwCIxNJC";int i=sizeof p/2;char *strchr();int putchar(\
);while(*q){i+=strchr(p,*q++)-p;if(i>=(int)sizeof p)i-=sizeof p-1;putchar(p[i]\
);}return 0;}

Flash Gordon
Guest
Posts: n/a

 02-14-2007
Malcolm McLean wrote, On 14/02/07 22:50:
> "Jamie Boy" <(E-Mail Removed)> wrote in message n
>>> Can anyone tell how to measure the size of an array without use of
>>> sizeof operator ?

>>
>> (char*)pover - (char*)p
>>
>>

> Make that unsigned char *.
> char * should be reserved for genuine character data, and can contain trap
> representations. A highly unlikely but allowable implementation could even
> crash your program if one of the pointers points to a trap representation.

What the pointers point to is irrelevant since they are not dereferenced
so casting to char* is fine. The problem with it is how you determine
the correct value of pover before you know the size of the array.
--
Flash Gordon