Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automatically Calc struct size??

Status
Not open for further replies.

rustywaters

Programmer
Sep 27, 2002
1
US
Hi,
I am trying to remember how I used to automatically calculate the size of a struct, inside the struct:

for example:
struct myStruct
{
int miInt;
int miAnotherInt;
char mcChar;
int *mpiPInt;
/* SOMETHING HERE such as : */
int miSizeofmyStruct = OFFSETOF(miSizeofmyStruct) - OFFSETOF(miInt);
}; /* OR SOMETHING LIKE THIS */

any help??
 
I'm not sure what OFFSETOF does but you have to add sizeof(miSizeofmyStruct) to it. The main problem is word alignment. The size of a struct varies according to the alignment.

Why not just use sizeof (struct myStruct)?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top