mdsplus icon indicating copy to clipboard operation
mdsplus copied to clipboard

c++ Int8 (and Array) types use implementation defined behavior

Open kgerickson opened this issue 3 years ago • 0 comments

The Int8 and Int8Array types assume that a "char" is a signed 8-bit integer. The standard doesn't specify this, and deliberately allows it to be signed or unsigned. The canonical type for a signed 8-bit int is std::int8_t, which is usually a typedef for "signed char". However, in C++, you cannot implicitly cast a "signed char" to a "char", resulting in compilation errors when trying to use the correct type of std::int8_t.

Fixing this is not so trivial, as the use of "char" is somewhat widespread.

Note that UInt8 similarly assumes "unsigned char" instead of "std::uint8_t", but that is slightly less problematic given that char is still being qualified.

In principle, all of these classes should be using stdint types, but maybe this permeates too far down into the underlying C library.

kgerickson avatar Jun 25 '21 01:06 kgerickson