Hi all,
Can we define a stuct which include some pointers, some may point to variables in global mem or registers, some may point to other struct?
Can we implement a link list or a state machine in the device?
something like this:
typedef struct g_states_t
{
int i;
struct g_states_t *pnext;
}g_state;
typedef struct ST_t
{
g_states_t **cur;
g_states_t *ctx[4];
}ST;
//★[A]Is this right?
__device__
g_states_t states[4] =
{
 {400, &states[1]},
 {401, &states[2]},
 {402, &states[3]},
 {403, &states[0]}
};
__global__ void kernel()
{
ST s1, *ps1;
ps1 = &s1;
//★[B]can we fetch the device var address simply by "&"?
ps1->ctx[0] = &states[0];
ps1->ctx[1] = &states[1];
ps1->ctx[2] = &states[2];
ps1->ctx[3] = &states[3];
/*★[C]what about this? Because when use "for loop" to assign, I found compile error(Advisory: Cannot tell what pointer points to, assuming global memory space) in Release but not in EmuDebug. The problem addle my brain.  */
// Â for (int i = 0; i < 4; i++)
// Â {
// Â Â ps1->ctx[i] = &states[i];
// Â }
/*★[D] The code seg below cause the advisory! Are these access manners legal?*/
ps1->ctx[2]->i = 123;
ps1->ctx[2]->pnext = NULL;
ps1->ctx[2]->pnext = &states[0];
ps1->ctx[3]->pnext->i = 456;
ps1->ctx[3]->pnext->pnext->i = 789;
}
I appreciate anybody give me some advice!
Thanks!
[attachment=5834:attachment]
