Goldschmidt Simon wrote:
>> Please look at mem.h, line 83:
>> void *mem_calloc(size_t count, size_t size);
>>
>> We think that the type should be mem_size_t, not just size_t;
>>
>> Under VisualC there is no problem because size_t is defined.
>> However, when we ported the source to the embedded target, its
> compiler complained.
>> typedef u16_t size_t; solves the problem, but it's not the right way
> to do it.
>> Are we right?
>
> As far as I know, the type 'size_t' is C-standard. If it is not defined
> on your platform, you will have problems with the socket layer also. If
> it is not defined, defining it in your port's 'cc.h' will be the right
> thing to do.
It is C standard, but only if you have #included <stddef.h>. Perhaps that's
what mem.h should do if it is referencing size_t.
I agree that <stddef.h> should be included.
But I still think it should be mem_size_t. Read carefully:
There is a stripped copy/paste from the source of mem.h:
#if MEM_SIZE > 64000l
typedef u32_t mem_size_t;
#define MEM_SIZE_F U32_F
#else
typedef u16_t mem_size_t;
#define MEM_SIZE_F U16_F
#endif /* MEM_SIZE > 64000 */
....
#if MEM_LIBC_MALLOC /* aliases for C library malloc() */
...
#else /* MEM_LIBC_MALLOC */
...
void *mem_malloc(mem_size_t size);
void *mem_calloc(size_t count, size_t size); // mem_size_t???
...
#endif /* MEM_LIBC_MALLOC */
This is from mem.c, line 564:
void *mem_calloc(size_t count, size_t size)
{
void *p;
p = mem_malloc(count * size);
if (p) {
memset(p, 0, count * size);
}
return p;
}
mem_size_t is 16 or 32-bit long, depending on the
system memory available.
Notice that mem_calloc() takes size_t argument
and passes it to mem_malloc() which, however, takes mem_size_t;
While size_t and mem_size_t happen to be both of the same length,
everything is OK.
Guess what happens when size_t is 32-bit, and mem_size_t is 16-t long.
I noticed some more "mistakes" like this one,
but I'll post them separately if you don't mind.
Regards
Iordan Neshev
Daisy Technology
|