1

我正在研究嵌入式 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;

谢谢 ....

4

4 回答 4

4
  1. p->psAplApsmeBindingTable->pvAplApsmeBindingTableEntryForSpSrcAddr->someField
  2. 没有不同。

PS。那个代码真的,真的很丑。

于 2012-02-20T18:57:08.773 回答
2
ZPS_tsAplApsmeBindingTable* psAplApsmeBindingTable; 

ZPS_tsAplApsmeBindingTable *psAplApsmeBindingTable; 

ZPS_tsAplApsmeBindingTable * psAplApsmeBindingTable; 

都是一样的。的位置*不会改变任何东西。


要访问由指针(如指针p)指向的结构的值,您可以使用箭头->

p->psAplApsmeBindingTable->pvAplApsmeBindingTableEntryForSpSrcAddr->u16ClusterId
于 2012-02-20T18:59:34.563 回答
1

我已经声明了 ZPS_tsAplApsmeBindingTableType *p; 但我想访问 ZPS_tsAplApsmeBindingTableEntry 结构值......我该怎么做?

好吧,你不能。在您的代码中 aZPS_tsAplApsmeBindingTableType不包含任何类型的成员ZPS_tsAplApsmeBindingTableEntryor ZPS_tsAplApsmeBindingTableEntry*

谁能告诉我 ZPS_tsAplApsmeBindingTable* psAplApsmeBindingTable 和 ZPS_tsAplApsmeBindingTable *psAplApsmeBindingTable 之间的区别;

没有区别; 它们是相同的东西...实际上是相同的文本复制了两次。我真的不明白你的问题。如果您能详细说明一下,我可能会提供进一步的帮助。

于 2012-02-20T18:55:49.203 回答
0

ZPS_tsAplApsmeBindingTableEntry将按以下方式访问成员:

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

等等。您将使用->用于所有选择,因为p,psAplApsmeBindingTablepvAplApsmeBindingTableEntryForSpSrcAddr都是指向结构类型的指针。如果它们中的任何一个不是指针类型,那么您将使用.运算符为该类型进行组件选择。例如:

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;

onlya将被声明为指向T; b将被声明为普通的T.

于 2012-02-20T20:13:27.703 回答