I have seen this question asked various times but for some reason when I attempt to use offsetof with the stddef.h header it will not resolve this macro in my eclipse IDE. Instead I am trying to access the structure by calculating it manually. This structure consists of only pointers.
Here is the code I currently have.
int chkpinmode(int header, int pin)
{
/*
* WARNING: This piece of code has no error checking yet!
*/
//Calculations...
unsigned int pinoffset=0;
if(header==8)
{//byte offset
pinoffset=((pin-2)*4);
}
else if(header==9)
{//byte offset
pinoffset=( (44 * 4)+( pin - 11 ) * 4 );//Defines at what point to look at the structure
}
char * pinConf=(char *)(&pins+pinoffset);//No need to worry about padding because structure is made up of pointers
int pinConfValue=-10;
pinConfValue=(int)pinConf;
int mode;
mode=(int)(pinConfValue&7);//Checks one the first 3 bits
return mode;
}
The structure is a long list of volatile int * with one volatile void * and it given addresses by another function. The header file has
extern pins;
which is the structure. So by the time function chkpinmode is called all the addresses are set.