1

I am working on Embedded C . I am stuck with pointer structure ....

Structures are given below ..

/*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;

I have declared ZPS_tsAplApsmeBindingTableType *p; but i want to access ZPS_tsAplApsmeBindingTableEntry structure values... How could i do that??

Can anyone tell me the difference between

ZPS_tsAplApsmeBindingTable* psAplApsmeBindingTable

and

ZPS_tsAplApsmeBindingTable *psAplApsmeBindingTable;

Thanks ....

Kerrek SB
  • 464,522
  • 92
  • 875
  • 1,084
Shantanu Banerjee
  • 1,417
  • 6
  • 31
  • 51

4 Answers4

4
  1. p->psAplApsmeBindingTable->pvAplApsmeBindingTableEntryForSpSrcAddr->someField
  2. No difference.

PS. That code is really, really ugly.

James M
  • 18,506
  • 3
  • 48
  • 56
  • and I think ZPS_tsAplApsmeBindingTable* psAplApsmeBindingTable is a array of structure ...if i use psAplApsmeBindingTable[0].someval or psAplApsmeBindingTable->someptr its showing a illegal address alignment – Shantanu Banerjee Feb 21 '12 at 03:37
2
ZPS_tsAplApsmeBindingTable* psAplApsmeBindingTable; 

and

ZPS_tsAplApsmeBindingTable *psAplApsmeBindingTable; 

and

ZPS_tsAplApsmeBindingTable * psAplApsmeBindingTable; 

Are the same. The location of the * does not change anything.


To access values of a struct pointed to by a pointer (like your pointer p), you can use an arrow ->

p->psAplApsmeBindingTable->pvAplApsmeBindingTableEntryForSpSrcAddr->u16ClusterId
Sam DeHaan
  • 10,246
  • 2
  • 40
  • 48
  • but sir it's show me error .. ZPS_tsAplApsmeBindingTable* psAplApsmeBindingTable its a array of structure pointed by psAplApsmeBindingTable.. if i use p->psAplApsmeBindingTable[0].u64SourceAddress again its show error.. please suggest a way to solve it.. – Shantanu Banerjee Feb 21 '12 at 03:42
  • have you tried `p->psAplApsmeBindingTable[0]->u64SourceAddress ` ? – Sam DeHaan Feb 21 '12 at 13:50
1

I have declared ZPS_tsAplApsmeBindingTableType *p; but i want to access ZPS_tsAplApsmeBindingTableEntry structure values... How could i do that??

Well you can't. In your code a ZPS_tsAplApsmeBindingTableType does not contain any members of the type ZPS_tsAplApsmeBindingTableEntry or ZPS_tsAplApsmeBindingTableEntry*.

Can anyone tell me the difference between ZPS_tsAplApsmeBindingTable* psAplApsmeBindingTable and ZPS_tsAplApsmeBindingTable *psAplApsmeBindingTable;

There is no difference; they are the same thing... literally the same text copied twice. I don't really understand your question. If you could elaborate a bit I may be able to help further.

Ed S.
  • 122,712
  • 22
  • 185
  • 265
  • suppose when a array of structure is pointed by a structure pointer ZPS_tsAplApsmeBindingTable* psAplApsmeBindingTable its a structure pointer .... i want to access those values in that location ... – Shantanu Banerjee Feb 21 '12 at 03:32
0

You'd get to the ZPS_tsAplApsmeBindingTableEntry members as follows:

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

etc. You would use the -> for all selections because p, psAplApsmeBindingTable, and pvAplApsmeBindingTableEntryForSpSrcAddr are all pointers to struct types. If any of them had not been pointer types, you would have used the . operator to do the component selection for that type. For example:

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

The expression x->y is shorthand for (*x).y; IOW, you dereference x and then select y.

There is no difference between the declarations

T *p;

and

T* p;

Both are interpreted as T (*p); - the * is always part of the declarator, not the type specifier. If you wrote

T* a, b;

only a would be declared as a pointer to T; b would be declared as a plain T.

John Bode
  • 119,563
  • 19
  • 122
  • 198