You are missing the (local) inbetween assignment declaration. Try this:
void main()
{
VECTOR v0;
vec_set(v0, vector(1,2,3));
VECTOR *v1 = &v0, *v2; // v2 is not a pointer to a vector as v1
v2 = v1; // wrong
while(1){
DEBUG_VAR(v2.x, 20);
DEBUG_VAR(v2.y, 40);
DEBUG_VAR(v2.z, 60);
wait(1);
}
}
VECTOR is also not a good example because it's a typedef struct.
This runs correct because var2 is a short pointer and not a short data:
function main()
{
short *var1 = sys_malloc(10*sizeof(short)), var2;
int i;
for (i=0; i<10; i++)
var1[i] = i;
var2 = var1; // correct
printf("%d", var1[6]);
printf("%d", var2[6]); // Expected result "6"
}
This is wrong, because var2 becomes a pointer to a short pointer:
function main()
{
short *var1 = sys_malloc(10*sizeof(short)), *var2;
int i;
for (i=0; i<10; i++)
var1[i] = i;
var2 = var1; // wrong
printf("%d", var1[6]);
printf("%d", var2[6]); // Not expected result "6"
}
This is correct, because var2 is handled as a pointer to a pointer:
function main()
{
short *var1 = sys_malloc(10*sizeof(short)), *var2;
int i;
for (i=0; i<10; i++)
var1[i] = i;
var2 = &var1; // correct
printf("%d", var1[6]);
printf("%d", *((*var2) + 6)); // Expected result "6"
}