false alarm __device__ printf bug? CUDA 6.0 K20c

I have a nested device function (which does not work).
The function is called from inside another device function from within a for loop
In an effort to debug cuda.cuh r1.16 I have added the following printf to the inner function
if(I==99 && blockIdx.x==0 && threadIdx.x==0)
printf("%d,%u,%u %d, %d\n",
0,lastpos,data,
0,0);
It appears to produce:
0,0,67107912 0, 67107872

I would expect I to be 99 on the first iterration of the for loop.
I cannot see why it prints “67107872” rather than “0”.

Any help or comments would be most welcome
Bill
http://www.cs.ucl.ac.uk/staff/W.Langdon/

Are the variables ‘lastpos’ and ‘data’ of type ‘unsigned int’? If not, a type mismatch between data and format specifier may be the issue. Since we cannot see the rest of the code, it is also possible that the values of those variables are exactly as printed, just different from what you expect, maybe due to integer overflow or an implicit signed-to-unsigned conversion elsewhere in the code.

Dear njuffa,
Thank you for your rapid reply.
Here is the inner function’s header
device unsigned char read_char(const int I, unsigned int * lastpos, unsigned int * data )

If it makes any difference, at this point (I would expect) both lastpos and data to be
pointers to variables which had not been assigned a value. read_char() sets them both up.

Is there anything which would cause %d to pick up rubbish in place of the zero passed to printf() ?

Thanks again
Bill

Based on the function prototype, ‘lastpos’ and ‘data’ are pointers. Thus your printf() should either be:

printf("%d,%p,%p %d, %d\n", 0,lastpos,data, 0,0);

or

printf("%d,%u,%u %d, %d\n", 0, *lastpos, *data, 0,0);

BTW, you subject title says “another device printf bug?” I am not aware of any previous confirmed bugs in device-side printf, can you clarify?

ok have dereferenced lastpos and data:-(
And the problem goes away:-)

As an aside how should I print pointers in printf?
Should it be as “%lu” ie treat pointers as long

Sorry
Bill

There is a specific format specifier for pointers, as I showed in my previous post: %p

Thank you:-)