C++ 如何找出C中分配在堆上的数组的大小

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>

#define ARRAYSIZE(a) (sizeof(a))/(sizeof(a[0]))
#define ARRAYSIZEWITHPTR(a) (&(a)[1] - a)

int main (void){

int array[5] = {1,2,3,4,5};
int* pArray = array;
int* p = calloc(ARRAYSIZE(array), sizeof(int));

assert(NULL != p);

printf("size of array: %ld\n", ARRAYSIZE(array));
printf("size of pArray: %ld\n", ARRAYSIZE(pArray));
printf("size of p: %ld\n", ARRAYSIZE(p));
printf("size of pArray: %ld\n", ARRAYSIZEWITHPTR(pArray));
printf("size of p: %ld\n", ARRAYSIZEWITHPTR(p));

free(p);

return 0;
}


test.c: In function ‘main’:
test.c:5:33: warning: division ‘sizeof (int *) / sizeof (int)’ does not compute the number of array elements [-Wsizeof-pointer-div]
5 | #define ARRAYSIZE(a) (sizeof(a))/(sizeof(a[0]))
|                                 ^
test.c:15:35: note: in expansion of macro ‘ARRAYSIZE’
15 |   printf("size of pArray: %ld\n", ARRAYSIZE(pArray));
|                                   ^~~~~~~~~
test.c:11:8: note: first ‘sizeof’ operand was declared here
11 |   int* pArray = array;
|        ^~~~~~
test.c:5:33: warning: division ‘sizeof (int *) / sizeof (int)’ does not compute the number of array elements [-Wsizeof-pointer-div]
5 | #define ARRAYSIZE(a) (sizeof(a))/(sizeof(a[0]))
|                                 ^
test.c:16:30: note: in expansion of macro ‘ARRAYSIZE’
16 |   printf("size of p: %ld\n", ARRAYSIZE(p));
|                              ^~~~~~~~~
test.c:12:8: note: first ‘sizeof’ operand was declared here
12 |   int* p = calloc(ARRAYSIZE(array), sizeof(int));
|        ^


size of array: 5
size of pArray: 2
size of p: 2
size of pArray: 1
size of p: 1