espression must have a constant value
i have a static struct variable having struct members and have to access this members on change of a count. so instead of using a switch case statement to load respective struct member (address) into a pointer, i thought of defining a local array of pointers to point struct members. but i get above error. I tried to specifically define the struct at address 0xA0000000 of my parallel SDRAM using __attribute__ ((at(0xA0000000)))
how can this be achieved using an array of pointers??
PS: LPC1788 - but dont think the problem is architecture dependent.
//Definitions & declarations typedef struct TimeFormat { uint8_t hrs[4]; uint8_t mins[2]; uint8_t secs[2]; }AsciiTime; typedef struct ProtoDetail { uint8_t name[NAME_SIZE]; uint8_t dos[NAME_SIZE]; uint8_t type[NAME_SIZE]; uint8_t pen[5]; uint8_t pure[5]; }PName; typedef struct SetDetail { uint8_t apparatus[NAME_SIZE]; uint8_t temp[4]; uint8_t pwrfaildelay[2]; AsciiTime sync; AsciiTime mnfldtym; AsciiTime dwntym; AsciiTime haltduratn; }PSet; typedef struct TimeTableDetail { uint8_t sampleno[2]; AsciiTime stym; uint8_t rpm[3]; uint8_t vol[4]; uint8_t action[35]; }PTimetbl; typedef struct MDetails { uint8_t msno[2]; uint8_t mname[PROTO_NAME_SIZE]; uint8_t phvalue[4]; uint8_t volume[4]; }PMd; typedef struct ProDetail { PName PrdName; PSetup PrdSet; PTimetbl PrdTymTbl[25]; PMd PrdMd[4]; }PDetail;
void dataprocessfunc(void) { ... PName *pnam = &LoadedData.PrdName; PSet *pstup = &LoadedData.PrdSet; PTimetbl *pmed = &LoadedData.PrdTymTbl[0]; ... UTILS_ClearBuf((uint8_t*)pnam, sizeof(LoadedData.PrdName)); psrc = uart_rxbuf; pdst = pnam->name; cntr = 0; while(cntr<8) { if(isalnum(*psrc) || *psrc == ' ' || *psrc == '_' || *psrc == '-' || *psrc == '.') if(*psrc != SEPERATOR && *psrc != ':' ) *pdst++ = *psrc; if(*psrc++ == SEPERATOR) { cntr++; switch (cntr) { case 3: pdst = pnam->name; maxlen = sizeof(pnam->name); break; case 4: pdst = pnam->dos; maxlen = sizeof(pnam->dos); break; case 5: pdst = pnam->type; maxlen = sizeof(pnam->type); break; case 6: pdst = pnam->pen; maxlen = sizeof(pnam->pen); break; case 7: pdst = pnam->pure; maxlen = sizeof(pnam->pure); break; } } } semicol = 0; UTILS_ClearBuf((uint8_t*)pstup, sizeof(LoadedData.PrdSet)); pdst = pstup->apparatus; while(cntr<15) { if(isalnum(*psrc) || *psrc == ' ' || *psrc == '_' || *psrc == '-' || *psrc == '.') { if(*psrc != SEPERATOR && *psrc != ':' ) *pdst++ = *psrc; } if(cntr==11 && *psrc == ':') pdst = pstup->sync.secs; if(cntr==12 && *psrc == ':') pdst = pstup->mnfldtym.secs; if(cntr==13 && *psrc == ':') pdst = pstup->dwntym.secs; if(cntr==14 && *psrc == ':') { semicol++; if(semicol==2) { pdst = pstup->haltduratn.secs; } else if(semicol==1) { pdst = pstup->haltduratn.mins; } } if(*psrc++ == SEPERATOR) { cntr++; switch (cntr) { case 8: pdst = pstup->apparatus; maxlen = sizeof(pstup->apparatus); break; case 9: pdst = pstup->temp; maxlen = sizeof(pstup->temp); break; case 10: pdst = pstup->pwrfaildelay; maxlen = sizeof(pstup->pwrfaildelay); break; case 11: pdst = pstup->sync.mins; maxlen = sizeof(pstup->sync); break; case 12: pdst = pstup->mnfldtym.mins; maxlen = sizeof(pstup->mnfldtym); break; case 13: pdst = pstup->dwntym.mins; maxlen = sizeof(pstup->dwntym); break; case 14: pdst = pstup->haltduratn.hrs; *pdst++ = ' '; *pdst++ = ' '; maxlen = sizeof(pstup->haltduratn); break; } } } //... contd in next post
Kindly dnt look deeper into the standardization _the variable name or function names may not be as per standards_
the whole function is not pasted. just the part of it so as to give a idea.
static PDetail LoadedData;