I'm working on a cross-platform program that calls a function from a dynamic library with C linkage. I need to support multiple versions of this dynamic library, but between two of the versions I need to support, there is a function parameter that has changed from uint32_t
to uint64_t
.
If I pass this function a uint64_t
that contains value which is still representable as a uint32_t, is that safe to do even when the function's parameter is actually a uint32_t
?
Put more specifically:
If the source of the function as compiled into the dynamic library is:
extern "C" void foo(uint32_t param) {
...
}
Is it safe for me to use the function like so:
extern "C" void foo(uint64_t);
uint32_t value32 = 10; // Ensure value can be represented by uint32_t
uint64_t value64 = value32;
foo(value64);
If yes, is it safe to do this across different platforms? This program of mine supports 32-bit and 64-bit Windows (compiled as x86 for both), x86_64 macOS, arm64 macOS, x86 Linux, and x86_64 Linux.
extern "C"
strips param mangling in the identifier name. – Destroyeruint64_t
and pass a uint32_t or uint64_t caller side, letting the compiler sort out the upscale conversion in the case of the former. – Destroyer