It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center。
7年前关闭。
我在C中有这样的东西:
其中
在此之后,我收到
为什么?
编辑:我可以访问structTypeInstance的先前声明的字段。我唯一的预感是为structTypeInstance分配内存的地方还不够。那可能吗?
当你真正的意思
7年前关闭。
我在C中有这样的东西:
unsigned char a = structTypeInstance->b ;
其中
b
与a
具有相同的类型。在此之后,我收到
SIGSEGV
。为什么?
编辑:我可以访问structTypeInstance的先前声明的字段。我唯一的预感是为structTypeInstance分配内存的地方还不够。那可能吗?
最佳答案
是的,那是可能的。但是,由于您拒绝向我们显示声明structTypeInstance
的代码,因此相应结构的定义的整体含义,定义的位置,因此我们不确定。
有时,错误就像编写一样简单
struct FOOBAR {
char big[16380];
char b[4];
};
struct FOOBAR *foo;
foo = malloc (sizeof foo); /* Allocates just a handful of bytes. */
当你真正的意思
foo = malloc (sizeof *foo); /* Allocates enough for a complete struct FOOBAR. */
关于c - C中的SIGSEGV访问结构成员,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12407437/