Differences between char*1 and schar

I’m reading the help of fread and I have some questions about the data types char1 and schar. char1 is 8-bit single character, ans schar is 8-bit signed character, but which is the difference between single and signed. If single means unsigned, which is then the difference between char*1 and uchar, which is 8-bit unsigned character? In Matlab help schar is clasified as integer data type: Write data to binary file - MATLAB fwrite - MathWorks España

Is this a Matlab question or an Octave question?
I guess this is a mapping for the various C types. `char`, `signed char`, and `unsigned char` are distinct types in the C standard. All are 8-bit wide on most platforms (exceptions might be on very exotic hardware). But while the “signed-ness” is clear for `signed char` and `unsigned char`, it depends on the platform whether `char` is signed or not.

It is an Octave question. I understand that schar returns a value in the range [-128 127] and uchar returns a value in the range [0 255]. So they are equivalents to (int8, integer*1), and uint8, respectively. Am I right? In this case I think it could be noted in the fread help

IIUC, the mapping between the precision arguments and the corresponding Octave data types is done here:
octave: e3256a6e2e8e liboctave/util/data-conv.cc (gnu.org)

``````// Organized so most frequent precision appears first
if (s == "uint8")
retval = dt_uint8;
else if (s == "double" || s == "float64" || s == "real*8")
retval = dt_double;
else if (s == "single" || s == "float" || s == "float32" || s == "real*4")
retval = dt_single;
else if (s == "char" || s == "char*1")
retval = dt_char;
else if (s == "int")
retval = dt_int32;
else if (s == "uchar" || s == "unsignedchar")
retval = dt_uint8;
else if (s == "schar" || s == "signedchar")
retval = dt_int8;
else if (s == "int8" || s == "integer*1")
retval = dt_int8;
else if (s == "int16" || s == "integer*2")
retval = dt_int16;
else if (s == "uint16")
retval = dt_uint16;
else if (s == "int32" || s == "integer*4")
retval = dt_int32;
else if (s == "uint32")
retval = dt_uint32;
else if (s == "int64" || s == "integer*8")
retval = dt_int64;
else if (s == "uint64")
retval = dt_uint64;
else if (s == "short")
retval = dt_int16;
else if (s == "ushort" || s == "unsignedshort")
retval = dt_uint16;
else if (s == "uint" || s == "unsignedint")
retval = dt_uint32;
else if (s == "long")
retval = dt_int32;
else if (s == "ulong" || s == "unsignedlong")
retval = dt_uint32;
// FIXME: The following are undocumented precisions
else if (s == "longlong")
GET_SIZED_INT_TYPE (long long, );
else if (s == "ulonglong" || s == "unsignedlonglong")
GET_SIZED_INT_TYPE (unsigned long long, u);
else if (s == "logical")
retval = dt_logical;
else
(*current_liboctave_error_handler) ("invalid data type specified");
``````

So, from the perspective of Octave, `"uchar"` and `"uint8"` are mapped to the same datatype (and are essentially equivalent). Same for `"schar"` and `"int8"`.

Thank you very much. I suggest that the help of fread function read as

``````"uint8" (default)
"uchar"
8-bit unsigned integer.

"int8"
"integer*1"
"schar"
8-bit signed integer.

"char"
"char*1"
8-bit single character (signed or unsigned, depending on platform).

*****DELETE "uchar"
*****DELETE "unsigned char"
*****DELETE           8-bit unsigned character.

*****DELETE "schar"
*****DELETE "signed char"
*****DELETE           8-bit signed character.
``````

It appears to me that uchar, unsigned char, schar, and signed char are all accepted by Octave’s fread function and is required for compatibility with Matlab. So I don’t see why we should remove them from the list in the help text.

Sorry. I might have misunderstood your initial question. I thought it was about the conceptual difference between these different type names. And I guess that concept is leaned on the C data types.
But not all C data types have a corresponding Octave data type and vice versa. E.g., Octave doesn’t have a direct equivalent for `signed char` and `unsigned char`. (Those should better have been named `signed byte` and `unsigned byte` in the C standard imho to better reflect the conceptual difference.) Hence, it must use different types that “most closely” match the original data type to represent that data in Octave.
Also, the `char` class in Octave is always unsigned (independent on the platform). That is different for the C data type that “happens” to have the same name.

No, in my opinion they do not need to be removed, but moved to the integer part, i.e.,

``````"uint8" (default)
"uchar"
"unsigned char"
8-bit unsigned integer.

"int8"
"integer*1"
"schar"
"signed char"
8-bit signed integer.

"char"
"char*1"
8-bit single character (signed or unsigned, depending on platform).
``````

Actually, in Matlab (Write data to binary file - MATLAB fwrite - MathWorks España) uchar, unsigned char, schar and signed char are classified as integer data types instead of characters. I think that now can lead to confusion.