Possible bug on CUDA printf()

Hi, I think that there is something strange on the printf() function performed in the kernel code.

#include <iostream>
#include <numeric>
#include <stdlib.h>
#include <stdio.h>

__global__ void myPrint(int *data) {
	printf("Address: %x Value: %d %d\n",(unsigned long)data, data[0], data[0]);
}


int main(void)
{
	cudaSetDeviceFlags(cudaDeviceMapHost);

	int* h_a;
	int* d_a;

	cudaHostAlloc((void **)&h_a, sizeof(int), cudaHostAllocMapped);

	h_a[0] = 71;

	cudaHostGetDevicePointer((void **)&d_a, (void *)h_a, 0);

	myPrint<<<1,1>>>(d_a);
	cudaDeviceSynchronize();
	cudaFreeHost(h_a);

	return 0;
}

The output is:

Address: 0x2a00000 Value: 1 71

How it is possible?

Why for the first “data[0]” the output is 1?

Using %p or %lx instead of %x for your pointer will fix this.
Addresses are 64 bits wide but %x expects 32 bits.

Thank you. It works.