具有结构的字段的结构 [英] structs with fields that are structs
问题描述
是否可以访问结构的字段,该字段是
另一个结构的字段?防爆。 struct subStr {
int num1;
int num2;
};
struct myStr {
int num3;
subStr * lock;
};
struct myStr * info;
我尝试在num1中存储一个值,其中包含以下指令:
info-> lock-> num1 = 5;
并且出现了分段错误。
我正在使用共享内存,需要将所有内容放在一个结构中。
任何帮助将不胜感激。
Is it possible to access a field of a struct which is a field of
another struct? Ex. struct subStr{
int num1;
int num2;
};
struct myStr {
int num3;
subStr *lock;
};
struct myStr *info;
I tried to store a value in num1 with the instruction:
info->lock->num1 = 5;
and got a segmentation fault.
I am using shared memory and need to put everything in one struct.
Any help would be appreciated.
推荐答案
Patricia Van Hise写道:
Patricia Van Hise wrote:
是否可以访问结构的字段这是另一个结构的领域?防爆。 struct subStr {
int num1;
int num2;
};
struct myStr {
int num3;
subStr * lock;
我认为你的意思
struct subStr * lock;
};
struct myStr * info;
我试图在num1中存储一个值,其中包含以下指令:
info-> lock-> num1 = 5;
并且出现了分段错误。
Is it possible to access a field of a struct which is a field of
another struct? Ex. struct subStr{
int num1;
int num2;
};
struct myStr {
int num3;
subStr *lock;
I think you mean
struct subStr *lock;
};
struct myStr *info;
I tried to store a value in num1 with the instruction:
info->lock->num1 = 5;
and got a segmentation fault.
您是否将结构myStr的地址分配给info?如果是这样,你是否b $ b将struct subStr的地址分配给info-> lock?
-
Russell Hanneken
rg********@pobox.com
从我的地址中删除''g'以向我发送邮件。
Did you assign the address of a struct myStr to info? If so, did you
assign the address of a struct subStr to info->lock?
--
Russell Hanneken
rg********@pobox.com
Remove the ''g'' from my address to send me mail.
Patricia Van Hise写道:
Patricia Van Hise wrote:
是否可以访问结构的一个领域,是另一个结构的领域?防爆。 struct subStr {
int num1;
int num2;
};
struct myStr {
int num3;
subStr * lock;
我认为你的意思
struct subStr * lock;
};
struct myStr * info;
我试图在num1中存储一个值,其中包含以下指令:
info-> lock-> num1 = 5;
并且出现了分段错误。
Is it possible to access a field of a struct which is a field of
another struct? Ex. struct subStr{
int num1;
int num2;
};
struct myStr {
int num3;
subStr *lock;
I think you mean
struct subStr *lock;
};
struct myStr *info;
I tried to store a value in num1 with the instruction:
info->lock->num1 = 5;
and got a segmentation fault.
您是否将结构myStr的地址分配给info?如果是这样,你是否b $ b将struct subStr的地址分配给info-> lock?
-
Russell Hanneken
rg********@pobox.com
从我的地址中删除''g'以向我发送邮件。
Did you assign the address of a struct myStr to info? If so, did you
assign the address of a struct subStr to info->lock?
--
Russell Hanneken
rg********@pobox.com
Remove the ''g'' from my address to send me mail.
Patricia Van Hise写道:
Patricia Van Hise wrote:
struct subStr {
int num1;
int num2;
};
struct myStr {
int num3;
subStr * lock;
应该是:struct subStr * lock;
这个编译吗?不要用C ++编译器编译C代码
};
struct myStr * info;
我试图在num1中存储一个值说明:
info-> lock-> num1 = 5;
并且出现了分段错误。
struct subStr{
int num1;
int num2;
};
struct myStr {
int num3;
subStr *lock;
should be: struct subStr *lock;
does this compile? do not compile C code with a C++ compiler
};
struct myStr *info;
I tried to store a value in num1 with the instruction:
info->lock->num1 = 5;
and got a segmentation fault.
如何分配信息或锁定?你没有提供代码,num1的
访问权限是正确的但很可能信息或锁定不是
指向有效的内存块,请提供实际代码你使用。
-
John Tsiombikas(核/实验室)
nu ***** @ siggraph.org
http://thelab.demoscene.gr/nuclear/
这篇关于具有结构的字段的结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!