A
asit dhal
Can anyone tell how to measure the size of an array without use of
sizeof operator ?
sizeof operator ?
asit dhal said:Can anyone tell how to measure the size of an array without use of
sizeof operator ?
Can anyone tell how to measure the size of an array without use of
sizeof operator ?
Can anyone tell how to measure the size of an array without use of
sizeof operator ?
asit dhal said:Can anyone tell how to measure the size of an array without use of
sizeof operator ?
No.asit said: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.
Make that unsigned char *.Jamie Boy said:(char*)pover - (char*)p
Malcolm McLean said: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.
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.
Malcolm McLean said: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.
No, you are right. It only traps when it is a "lvalue", which doesn't meanBen Pfaff said:I don't believe this. Can you cite chapter & verse on that?
Can anyone tell how to measure the size of an array without use of
sizeof operator ?
(e-mail address removed) said:
You don't pass an array to a function. You pass a pointer to that
array's first element.
If you don't want to use the sizeof operator, two things that come to
mind are:
1) Keep track of the length of the array (or a pointer to the end) as
you build it, and that way you always know how big it is.
2) Put a sentinel value at the end of the array and the count the
number of elements from the start of the array until you hit the
sentinel.
The string library functions often work this second way, with a '\0'
character at the end of the array. That's how they know when to stop
counting, copying, printing, or whatever.
-Beej
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.