Re: Basic C query.
Re: Basic C query.
- Subject: Re: Basic C query.
- From: Rohitash Panda <email@hidden>
- Date: Wed, 23 Jun 2010 21:52:25 +0530
This is a classic case of trying to implement offsetof() as Peter
suggested , but having platform dependent behavior . This follows from
the below idiomatic construct of offsetof() implementation:
#define offsetof(type, field) ((size_t)((char *)&((type *)0)->field -
(char *)(type *)0))
Portable 'C' code should instead use the platform offsetof()
implementations available .
Peter O'Gorman wrote:
On 06/23/2010 09:53 AM, Arnab Ganguly wrote:
Dear All,
Sorry for posting a basic C question.Below is the code base.
struct Test
{
int a;
int b;
};
//member offset.
int result = (((Test *) 8)->a) - 8;
I get bus error for this. I am not clear about the logic as what exactly
((Test *) 8)->a signifies here and why -8 is done.
I have copy pasted a smaller portion of the main code.Only one line
written as Member offset. The above code works fine in 32bit but in
64bit I am getting issue if I can understand the above logic will be
more clear as what needs to be done.
Use offsetof()
http://en.wikipedia.org/wiki/Offsetof
Peter
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden