hi,  i have encountered something really strange, though...

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

hi,  i have encountered something really strange, though...

1,963 次查看
dashz84
Contributor I
hi,

i have encountered something really strange, though it may be the result of my limited experience with C.

when I initialized an array of int by saing

int array[]={0, 20, 40, 60 , 80, 100};

inside the Debugger, every value of array was set to -1.

also, if i initalize the array by saying

unsigned int array[]={the same as above};

the the debugger says that all the elements are equal to 65535.

Can someone please tell me what might be the possible causes for these symptoms?

thanks very much
标签 (1)
标记 (1)
0 项奖励
回复
2 回复数

1,101 次查看
dashz84
Contributor I
i also forgot to mention that if i specify the array as

int array={1,2,3,4,5} then the array is produced with the correct values,
however the code
int array={1,2,3,4,5,6,7,8,9,10} does not produce the desired array, instead it's an array of {1}'s.

furthermore, if I use 'unsigned int', instead of 'int', then i can only accuratly initialize the array with only 1 element, i.e. unsigned int array={1} is the only array length that woks.

any help is much appreciated
0 项奖励
回复

1,101 次查看
bigmac
Specialist III
Hello,
 
I assume that it is your intent that the array variable be located in RAM, and is declared as a global variable.  If so, when the project is created you will need to enable ANSI initialisation, for global variables to be properly initialised during startup.
 
Does this apply to your project?
 
Regards,
Mac