Jump to content

View more

Image of the Day

The night is still, but the invasion brings chaos. #screenshotsaturday #hanako #indiegame #gameart #ue4 #samurai https://t.co/cgILXuokoS
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

Struct member offsets

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
2 replies to this topic

#1 Tispe   Members   

1468
Like
0Likes
Like

Posted 28 March 2012 - 05:54 AM

Hi

Say you have a char pointer "p" to an array of characters. Now p+1 would give you the second character and so on.

The same applies for structs. If a struct is 40 Bytes long, then structobject+1 increments by 40 bytes.

How does this applies to members of a struct?

struct MyStruct
{
  int   no;
  int   idx_x,idx_y,idx_z;
  float tx,ty,tz,tw;
};


MyStruct &pData = ArrayOfMyStructs[47];
int offset = 3;
pData.no+offset;    //Where is this address?

Does pData.no+offset; refer to ArrayOfMyStructs[50].no, or does it refer to ArrayOfMyStructs[47].idx_z?

#2 Brother Bob   Moderators   

10278
Like
3Likes
Like

Posted 28 March 2012 - 06:06 AM

When pData is a pointer, then pData.no is not valid syntax to begin with. But even if you meant pData->no, then pData->no+3 simply means the value of the no-member plus three.

If, on the other hand, you meant (&pData->no)+3, then that is equivalent to int *pNo=(&pData->no); pNo+3 which moves an int-pointer three steps forwards. In practice, that would mean it likely points to ArrayOfMyStructs[47].idx_z.

#3 Tispe   Members   

1468
Like
0Likes
Like

Posted 28 March 2012 - 06:10 AM

Thank you :)




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.