This is the working original code:
// ...
unsigned __int64 num = 57;
sprintf_s(buffer, sizeof(buffer), "%llu", num);
However, when I try to extract this part into this function:
void addBuffered(void** attributeValue, char* format)
{
sprintf_s(buffer, sizeof(buffer), format, *attributeValue);
}
by calling:
addBuffered((void**)&num, "%d");
I have to change the format parameter in sprintf_s from %llu to %d to get the correct value. Can somebody explain why this happens and if the change of the parameter to %d can be a problem? Thanks!
This happens because
sizeof(void *) == 4in your case. And you implicitly cast__int64tovoid *by function call. So if you use%lluformat, you print some garbage from memory.I suggest you to rewrite function if it is possible:
call example: