2
I have a question regarding the array, for example, if I have 2 arrays of size 9 and print the values of both it is normal for input 9 to get the value 0 of the next array ? This is more of a test, I know the maximum is 8 ?
Code example:
struct stType {
type[9];
}select;
strcut vrType {
type[9];
}variable;
void st_type(int type, int value) {
int i;
uint32 type_select = select_type(type);
ST_TYPE(i, type_select) {
select->type[i] += value;
}
}
void vr_type(int type, int value) {
int i;
uint32 type_select = variable_type(type);
VR_TYPE(i, type_select) {
variable->type[i] += value;
}
}
int main() {
st_type(0, 50); // define valor 50 para array select->type[0]
vr_type(0, 60); // define valor 60 para array variable->type[0]
for (i = 0; i < 10; i++)
printf("[ST Debug %d] Value: %d\n", i, select->type[i]);
printf("\n");
for (i = 0; i < 10; i++)
printf("[VR Debug %d] Value: %d\n", i, variable->type[i]);
}
Exit:
[ST Debug 0] Value: 50
[ST Debug 1] Value: 0
[ST Debug 2] Value: 0
[ST Debug 3] Value: 0
[ST Debug 4] Value: 0
[ST Debug 5] Value: 0
[ST Debug 6] Value: 0
[ST Debug 7] Value: 0
[ST Debug 8] Value: 0
[ST Debug 9] Value: 60 // posição 9 puxa o 0 de vr
[VR Debug 0] Value: 60
[VR Debug 1] Value: 0
[VR Debug 2] Value: 0
[VR Debug 3] Value: 0
[VR Debug 4] Value: 0
[VR Debug 5] Value: 0
[VR Debug 6] Value: 0
[VR Debug 7] Value: 0
[VR Debug 8] Value: 0
[VR Debug 9] Value: 0
I see, but it hurts something in the code ?
– Carol
Very, you’re accessing an area that shouldn’t, what you have there is considered garbage, and you’ll consume it. Worse, moving there will alter something that is part of another object damaging it.
– Maniero