c - Shifting array elements returns unexpected value -
i programming stm32 arm based board , following problem:
i moving elements inside array unexpected values not part of array. here code:
int temp=*manual_items[selec].byte_control[2]; *manual_items[selec].byte_control[2]=*manual_items[selec].byte_control[1]; *manual_items[selec].byte_control[1]=*manual_items[selec].byte_control[0]; *manual_items[selec].byte_control[0]=temp;
the values inside array (0,0,1) example, expect (0,1,0) but, instead (224,1,0). makes me suspect kind of garbage being stored in temp, have tried initializing 0 when declared, getting same result.
also, using same approach in different part of code works:
int temp=*manual_items[selec].byte_control[3]; *manual_items[selec].byte_control[3]=*manual_items[selec].byte_control[2]; *manual_items[selec].byte_control[2]=*manual_items[selec].byte_control[1]; *manual_items[selec].byte_control[1]=*manual_items[selec].byte_control[0]; *manual_items[selec].byte_control[0]=temp;
this shifts values perfectly, can't understand why first not working , second yes. problem?
if helps, i'm using keil uvision 5 ide.
ps: know there better ways shift values in arrays, test doing.
edit: manual_items[] array of manual_t, struct created. struct:
typedef struct _manual_ { char name[20]; uint8_t *byte_control[4]; status_t *status; status_type type; int color_ref; char display_ref[10]; } manual_t;
so byte_control[] of type uint8_t.
edit 2: declartion of manual_items:
manual_t manual_items[]= { {"barrier",{&barrierman},&status_items[3],updown,0,0}, {"sem. 1",{&sem1greenman,&sem1yellowman,&sem1redman},&status_items[8],semaphore,0,0}, {"sem. 2",{&sem2greenman,&sem2yellowman,&sem2redman},&status_items[9],semaphore,0,0} };
edit 3: works!! in end problem not related piece of code, why not find causing error. had forgotten put break;
after 2 switch case
s, made program go crazy. , remember mistakes expect least!
Comments
Post a Comment