是否有一种方法可以从结构类型指针(STP)获取结构的大小,而无需先通过STP声明结构?
这个类似的问题没有我的问题的有效答案:dereferencing pointer to incomplete type - typedef struct
#include <stdlib.h>
#include <stdio.h>
typedef struct S * STP;
struct S {
uint64_t a;
uint64_t b;
};
int main() {
STP A = (STP)malloc(sizeof(STP)); // allocates poiner size
printf("Size STP: %lu\n", sizeof(STP));
STP B;
B = (STP)malloc(sizeof(*B)); // allocates expected struct size
printf("Size B: %lu\n", sizeof(*B));
free(A);
free(B);
}