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

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

1,214 Views
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
Labels (1)
Tags (1)
0 Kudos
2 Replies

352 Views
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 Kudos

352 Views
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