Originally Posted by
rcgldr
The program is printing the address of the allocated memory, not the size. malloc() doesn't return the size of the actual amount of memory allocated. malloc() uses internal structures to keep track of the amount of allocated memory, but those structures will be different depending on the operating system and/or the compiler being used. A program wouldn't normally be able to access those internal structures, so there's no real way to verify the size requested, other than to trust that malloc() worked if it returns a non-NULL pointer.
I think you're confusing the op now. Perhaps this will make things clear:
Code:
char * p;
size_t sz = 7 * sizeof *p;
if (p = malloc(sz))
fprintf(stderr, "Successfully allocated _at least_ %lu bytes at pointer %p\n", sz, p);
else
fprintf(stderr, "Failed to allocate %lu bytes\n", sz);