matevzb said:
> On Jan 2, 3:18 pm, Richard Heathfield <r...@see.sig.invalid> wrote:
>> matevzb said:
>>
>> > On Jan 2, 1:10 pm, dbtid <dbt...@nospam.gmail.com> wrote:
>> >> For objects declared as arrays, sizeof(a) will work just fine.
>>
>> > No, it will not.
>> Yes, it will. But the OP can't use sizeof because he's not actually
>> getting an array, merely a pointer.
> Indeed, that's another way of interpreting "sizeof(a) will work just
> fine". What I meant was "no, it will not work as a means of getting
> information about array size" (which I presumed dbtid suggested) and
> not "sizeof(a) will not work fine", which of course it always should.
Well, actually you have misinterpreted me, albeit in a way that does not
give rise to any C-ontradictions so it probably doesn't matter. What does
matter (and I think we are in full agreement here) is this:
#include <stddef.h>
void foo(int *p)
{
size_t x = sizeof p; /* gives size of pointer, in bytes, probably 4 */
}
void bar(int *q, size_t nobj)
{
while(nobj--)
{
*q++ = 42;
}
}
int main(void)
{
int arr[20] = {0};
size_t y = sizeof arr; /* gives size of array, in bytes, probably 80 */
foo(arr); /* not good enough */
bar(arr, sizeof arr / sizeof arr[0]); /* good enough */
return 0;
}
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.