Hi everyone,
I'm working on something that needs to be cross platform, and I have uint64_t and int64_t variables I need to use in printf and snprintf calls. I landed on using the "PRIu64" and "PRId64" format specifiers from inttypes.h (if you have a better suggestion for cross platform support, please let me know!), which is working well
on both windows and linux for my code that is pure c, but I'm not sure how to implement it in the cython portions of my code. This is also complicated by the fact that I'll be using it in a nogil block.
The standard C usage of PRIu64 would be
#include <inttypes.h>
uint64_t number = 5000;
printf("number = %" PRIu64 "\n", number);
I have the below code in a separate .pyd that I cimport from (though I'm not sure if this is the proper way to utilize a C string literal of variable length that was defined):
cdef extern from "<inttypes.h>" nogil:
char *PRIu64
char *PRId64
When attempting to use in cython code, it only seems to work if I remove "nogil", and use the standard "+" based string concatenation:
printf("%" PRIu64 "other text"
, number)
error: Expected ')', found 'PRIu64'
printf("%" + PRIu64 + "other text"
, number)
error: Operation not allowed without gil (on the "+")
error: Converting to Python object not allowed without gil (on PRIu64)
The last one works without nogil.
Any thoughts on how to utilize these format specifiers in cython? Thank you for the help!