//C code(hello.cpp):
typedef struct g_states_t
{
int i;
struct g_states_t *pnext;
}g_state;
typedef struct ST
{
g_states_t **cur;
g_states_t *ctx[4];
}ST;
void setstates(ST *ps, g_states_t states[4])
{
for (int i = 0; i < 4; i++)
{
ps->ctx[i] = &states[i];
}
}
void main(int argc, char * argv[])
{
g_states_t states[4] =
{
{400, &states[1]},
{401, &states[2]},
{402, &states[3]},
{403, &states[0]}
};
ST s1, *ps1;
ps1 = &s1;
setstates(ps1, states);
ps1->ctx[2]->i = 123;
ps1->ctx[2]->pnext = &states[0];
ps1->ctx[3]->pnext->i = 456;
printf("%d\n", ps1->ctx[2]->i);//ok,output:123
printf("%d\n", ps1->ctx[2]->pnext->i);//ok,output:456
printf("%d\n", ps1->ctx[3]->pnext->i);////ok,output:456
printf("hello");
}
/////////////////////////////////////////////
//GPU code(kernel.cu):
typedef struct g_states_t
{
int i;
struct g_states_t *pnext;
}g_state;
typedef struct ST
{
g_states_t **cur;
g_states_t *ctx[4];
}ST;
__device__
void setstates(ST *ps, g_states_t states[4])
{
for (int i = 0; i < 4; i++)
{
ps->ctx[i] = &states[i];
}
}
__global__
void kernel()
{
g_states_t states[4] =
{
{400, &states[1]},
{401, &states[2]},
{402, &states[3]},
{403, &states[0]}
};
ST s1, *ps1;
ps1 = &s1;
setstates(ps1, states);
ps1->ctx[2]->i = 123;//err
ps1->ctx[2]->pnext = &states[0];//err
ps1->ctx[3]->pnext->i = 456;//err
}
/////////////////////////////////////////////////////////////////////////////////
When compile the GPU code in Release mode,prompt:
1>------ å·²å¯åŠ¨ç”Ÿæˆ: 项目: cu_blank_forTest, é…ç½®: Release Win32 ------
1>æ£åœ¨æ‰§è¡Œè‡ªå®šä¹‰ç”Ÿæˆæ¥éª¤
1>cu_host.cu
1>tmpxft_00001ae8_00000000-3.gpu
1>tmpxft_00001ae8_00000000-7.gpu
1>“E:\MYWIND~1\TEMP/tmpxft_00001ae8_00000000-8.i”, line 43: Advisory: Cannot tell what pointer points to, assuming global memory space
1>“E:\MYWIND~1\TEMP/tmpxft_00001ae8_00000000-8.i”, line 44: Advisory: Cannot tell what pointer points to, assuming global memory space
1>“E:\MYWIND~1\TEMP/tmpxft_00001ae8_00000000-8.i”, line 45: Advisory: Cannot tell what pointer points to, assuming global memory space
1>“E:\MYWIND~1\TEMP/tmpxft_00001ae8_00000000-8.i”, line 45: Advisory: Cannot tell what pointer points to, assuming global memory space
1>tmpxft_00001ae8_00000000-3.c
1>tmpxft_00001ae8_00000000-12.i
1>æ£åœ¨é“¾æŽ¥…
1>æ£åœ¨åµŒå…¥æ¸…å•…
1>生æˆæ—¥å¿—ä¿å˜åœ¨â€œfile://d:\Working\cu_blank_forTest\cu_blank_forTest\Release\BuildLog.htmâ€
1>cu_blank_forTest - 0 个错误,0 个è¦å‘Š
========== 生æˆ: 1 å·²æˆåŠŸ, 0 已失败, 0 最新, 0 已跳过 ==========
What’s the reason, please?