"Kevin C." <no****@fake.com> wrote in message
news:sD*******************@newssvr29.news.prodigy. com
udt_list *g_list = calloc(1, LIST_SIZE);
udt_entry *entry = get_entry(); // returns a pointer to some address
in g_list
int numbytes = (char*)entry - (char*)g_list; // supposed to be offset
in bytes
But numbytes is -240. Can someone explain why?
The fact that get_entry() doesn't take an argument is a clue that it doesn't
do what you think it does.
The following shows an example that works. It retrieves the offset of the
style field in a CREATESTRUCT struct. Compare it to what you are doing and
you should be able to figure out where you are going wrong.
LONG *GetStyleAddress(CREATESTRUCT * pcs)
{
return &pcs->style;
}
int main()
{
CREATESTRUCT *pcs = (CREATESTRUCT*)calloc(1, sizeofCREATESTRUCT));
LONG *pstyle = GetStyleAddress(pcs);
int numbytes = (char*)pstyle - (char*)pcs;
return 0;
}
If you were working with a linked list, then there is no necessary reason
for later list elements to have a higher address than earlier elements, but
the code you have supplied isn't consistent with a linked list.
--
John Carson
1. To reply to email address, remove donald
2. Don't reply to email address (post here instead)