Calling CPU code from the GPU It works for printf, but I can't get it to work for my code

I know that when my code is actually running on a GPU it is not going to be possible to get it to call back to the CPU. However, when I am debugging in the emulator, it would be useful to call back to the CPU to run code to help identify errors. It is possible to call printf just by including the header stdio.h, however it seems that things are not so simple for code I construct myself. Unless I prefix my code with device this just results in an error saying it is unable to find the function.

Is there something special about the functions in stdio.h (such as they have been reimplemented to allow this functionality), or am I just making a coding error. If it is the latter, could someone point me in the direction of an example of how I should construct the calls to other functions.

Many thanks