Dne 11.7.2011 05:40, Frédéric Marchal napsal(a):
On Sunday 10 July 2011 11:38:11 Mirek Jezbera wrote:
Hi Dominik,
I assume that sizeof(uint32_t) comes from a few lines above:
data = (uint32_t *)malloc(info_length);
Why not use sizeof(*data)?
Are you sure, that sizeof can determine size of memory allocated with
malloc? I think it can return size of statically allocated structures and
base types.
Just to keep track of the answer: malloc cannot determine the size of a
dynamically allocated object but that's not the purpose. sizeof(*data) returns
the size of one item pointed by data. It could be written as sizeof(data[0]).
It is computed at compile time and doesn't even require that data points to a
valid memory. sizeof(*data) will work even if data is NULL or invalid.
And for the record, sizeof(Data) is the size of a pointer. It is not the size
of the allocated memory.
Frederic
Hi Frederic,
thank you for your explanation. I have missed, that sizeof(*data) is
replacement of sizeof(uint32_t). I have wrongly thought, that Dominic
want to use sizeof to determine number of elements in data.
Jezz
_______________________________________________
DVDnav-discuss mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/dvdnav-discuss