We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
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.
#include <stdio.h> #include <stdint.h> typedef struct { uint8_t A1[10]; uint8_t A2[20]; uint8_t A3[30]; } Type_StA; typedef struct { uint8_t B1[10]; uint8_t B2[20]; uint8_t B3[30]; Type_StA PhStA; } Type_StB; Type_StB The_Struct; uint8_t * Array[] = { The_Struct.B1, The_Struct.B2, The_Struct.B3, The_Struct.PhStA.A3 }; int main(void) { The_Struct.B2[0] = '_'; The_Struct.B2[1] = 'B'; The_Struct.B2[2] = '2'; The_Struct.B2[3] = 0; The_Struct.PhStA.A3[0] = '_'; The_Struct.PhStA.A3[1] = 'A'; The_Struct.PhStA.A3[2] = '3'; The_Struct.PhStA.A3[3] = 0; printf("%s\n", Array[1] ); printf("%s\n", Array[3] ); return 0; }
Thank you John Linq. Thanks a lot! That was highly appreciable.