-
-
Notifications
You must be signed in to change notification settings - Fork 717
ENH: Replace 'char' with int8_t when numeric is intended #5795
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
The 'char' type can be signed or unsigned on different platforms and is generally used for ASCII character storage. To conistently represent 8-bit signed values on differnt platforms the int8_t type is recommended.
N-Dekker
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest using signed char, rather than int8_t, in a context that also deals with unsigned char in a similar way. However, that's no show-stopper to me. Just something to consider...
This PR was intended to take the first step towards some loose best-practices conventions scattered about stackoverflow/reddit/other sources:
In the instances you gave, I would prefer to use 'uint8_t' instead of 'unsigned char'. Given your statement that the current is OK, I am going to leave this PR as is and submit another PR in the near future with more instrumentation of 'int8_t' and 'uint8_t'. NOTE: I am teaching a graduate-level course that includes an important component on teaching best practices using ITK examples. My personal preference for int8_t and uint8_t is that they more clearly demonstrate to new developers (many of whom are first-time C++ programmers) that these are just very small integer data types. It is easy for these new programmers to understand that int8_t is an 8-bit integer. |
|
Thanks for explaining, Hans.
When the intent is just raw bytes, it might be preferable to use std::byte, as introduced with C++17 😇 |
The 'char' type can be signed or unsigned on different platforms
and is generally used for ASCII character storage. To conistently
represent 8-bit signed values on differnt platforms the int8_t
type is recommended.
PR Checklist