-1
我试图获取在不同的源文件(other.c)中定义的结构的大小以使其隐藏。获取隐藏结构的大小C
在other.h:
typedef struct X x_t;
在other.c:
struct X{
int y;
int z;
};
现在我想在main.c中得到这个结构的大小。
#include "other.h"
int main(){
x_t *my_x;
my_x = malloc(sizeof(struct x_t));
return 0;}
但是这给了我以下错误:
error: invalid application of ‘sizeof’ to incomplete type ‘struct x_t’
任何人可以帮助我吗?谢谢!
你不能这样做。如果你想'main.c'能够在'struct X'的实例(而不是指针)上运行,你需要在头文件中定义。 –
'sizeof'在编译时进行评估。如果'struct'不可见,则无法调整大小。 –
没有'struct x_t',只有'x_t'或'struct X'这样的事情 – user3078414