An array of uint3? How to do this if possible.

Hi,

I would like to create an array of 3d values :

array = [ {1,2,3},{4,5,6},{6,8,9}…]

using uint3 as basis.

I tried this:

#include <stdio.h>

int main()

{

uint3 *triad;

triad[0].x=1;

triad[0].y=2;

triad[0].z=3;

printf(" %d %d %d \n",triad[0].x,triad[0].y,triad[0].z);

}

but it does not work. It compiles with this warning:

warning: variable “triad” is used before its value is set

and segfault when running. Any idea if this is possible to do?

Thanks

This is about the third or fourth thread you have posted with fundamentally broken pointer usage in it, which suggests you need to spend some time and revise pointers and addressing in C.

At the moment triad is just a pointer (ie. a single unsigned 32 or 64 bit integer which can hold an address). You have told the compiler it will point to some memory containing uint3 values. But you have never declared or reserved any memory and given that address to triad. Which is why you get a warning that you are using it before it is set and then why it segfaults - you are trying to use the random contents of triad as an address, and it isn’t valid.

Thank you,

In the hope it helps some others!

This is the revised working code:

#include <stdio.h>

int main()

{

uint3 *triad;

triad = (uint3 *)malloc(1000);

triad[0].x=1;

triad[0].y=2;

triad[0].z=3;

printf(" %d %d %d \n",triad[0].x,triad[0].y,triad[0].z);

}