This line
printf("%d\n", *c);
pulls sizeof(*c)
bytes from the stack, from which only the first byte is valid memory, as allocated by:
int * c;
...
c = (int*) malloc(1);
As sizeof(*c)
definitly is larger then 1
the call to printf()
above provokes undeinfed behaviuor.
Allthough I cannot really parse this:
cudaMalloc((void**) &d_tidx, 1);
The 1
looks obscure to me.