2012-02-20 113 views
1

我正在处理嵌入式C.我坚持指针结构....卡住C指针结构

结构如下所示..

/*structure 1*/ 
ZPS_tsAplApsmeBindingTableType *psAplApsmeAibBindingTable; 

/*structure 2*/ 
typedef struct 
{ 
    ZPS_tsAplApsmeBindingTableCache* psAplApsmeBindingTableCache; 
    ZPS_tsAplApsmeBindingTable* psAplApsmeBindingTable; 
}ZPS_tsAplApsmeBindingTableType; 

/*structure3*/ 
typedef struct 
{ 
    uint64 u64SourceAddress; 
    ZPS_tsAplApsmeBindingTableEntry* pvAplApsmeBindingTableEntryForSpSrcAddr; 
    uint32 u32SizeOfBindingTable; 
}ZPS_tsAplApsmeBindingTable; 

/*structure 4*/ 
typedef struct 
{ 
    ZPS_tuAddress uDstAddress; 
    uint16 u16ClusterId; 
    uint8 u8DstAddrMode; 
    uint8 u8SourceEndpoint; 
    uint8 u8DestinationEndPoint; 
} ZPS_tsAplApsmeBindingTableEntry; 

我宣布ZPS_tsAplApsmeBindingTableType *p;,但我想访问ZPS_tsAplApsmeBindingTableEntry结构值...我怎么能做到这一点?

谁能告诉我

ZPS_tsAplApsmeBindingTable* psAplApsmeBindingTable 

ZPS_tsAplApsmeBindingTable *psAplApsmeBindingTable; 

感谢之差....

+3

我被困在你的命名约定!哇。当结构的阵列是由一个结构指针 ZPS_tsAplApsmeBindingTable * psAplApsmeBindingTable其结构指针指向 – Duck 2012-02-20 18:55:48

回答

4
  1. p->psAplApsmeBindingTable->pvAplApsmeBindingTableEntryForSpSrcAddr->someField
  2. 没有区别。

PS。这段代码真的很难看。

+0

当我使用它的产生非法地址对齐.. .. – 2012-02-21 03:29:46

+0

我认为ZPS_tsAplApsmeBindingTable * psAplApsmeBindingTable是结构的阵列...如果我使用psAplApsmeBindingTable [0] .someval或psAplApsmeBindingTable-> someptr其呈现出非法地址对齐 – 2012-02-21 03:37:38

1

我宣布ZPS_tsAplApsmeBindingTableType * P;但我想访问ZPS_tsAplApsmeBindingTableEntry结构值...我怎么能这样做?

那么你不能。在您的代码中,ZPS_tsAplApsmeBindingTableType不包含ZPS_tsAplApsmeBindingTableEntryZPS_tsAplApsmeBindingTableEntry*类型的任何成员。

谁能告诉我ZPS_tsAplApsmeBindingTable * psAplApsmeBindingTable和ZPS_tsAplApsmeBindingTable * psAplApsmeBindingTable之间的差异;

没有区别;他们是相同的东西......从字面上来看,相同的文本被复制两次。我真的不明白你的问题。如果你能详细阐述一下,我可能会进一步提供帮助。

+0

想....我想访问该位置的值... – 2012-02-21 03:32:28

2
ZPS_tsAplApsmeBindingTable* psAplApsmeBindingTable; 

ZPS_tsAplApsmeBindingTable *psAplApsmeBindingTable; 

ZPS_tsAplApsmeBindingTable * psAplApsmeBindingTable; 

相同*的位置不会改变任何内容。


一个struct的访问值指向指针(如您的指针p),您可以使用箭头->

p->psAplApsmeBindingTable->pvAplApsmeBindingTableEntryForSpSrcAddr->u16ClusterId 
+0

但爵士它告诉我错误.. ZPS_tsAplApsmeBindingTable * psAplApsmeBindingTable其一个由psAplApsmeBindingTable指向的结构数组..如果我使用 p-> psAplApsmeBindingTable [0] .u64SourceAddress再次显示错误..请建议一种方法来解决它.. – 2012-02-21 03:42:36

+0

你试过'p-> psAplApsmeBindingTable [0] - > u64SourceAddress '? – 2012-02-21 13:50:40

0

你会得到的ZPS_tsAplApsmeBindingTableEntry成员如下:

p->psAplApsmeBindingTable->pvAplApsmeBindingTableEntryForSpSrcAddr->uDstAddress 
p->psAplApsmeBindingTable->pvAplApsmeBindingTableEntryForSpSrcAddr->u16ClusterId 
p->psAplApsmeBindingTable->pvAplApsmeBindingTableEntryForSpSrcAddr->u8DstAddrMode 

等你会使用->的所有选择,因为ppsAplApsmeBindingTablepvAplApsmeBindingTableEntryForSpSrcAddr都指向结构类型。如果它们中的任何一个有而不是是指针类型,那么您应该使用.运算符来为该类型执行组件选择。例如:

struct a {int x; int y}; 
struct b {struct a *p; struct a v}; 
struct b foo, *bar = &foo; 
... 
foo.p->x = ...; // foo is not a pointer type, p is a pointer type 
bar->v.y = ...; // bar is a pointer type, v is not a pointer type 

表达x->y是简写(*x).y; IOW,您解除引用x,然后选择y

有声明

T *p; 

T* p; 

两者都解释为T (*p);之间没有区别 - *总是声明符,而不是类型说明符的一部分。如果你写

T* a, b; 

a将被声明为指针,以T; b将被宣布为普通T