Skip to content

Conversation

@hjmjohnson
Copy link
Member

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

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.
@github-actions github-actions bot added type:Enhancement Improvement of existing methods or implementation type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct area:Bridge Issues affecting the Bridge module area:Core Issues affecting the Core module area:Filtering Issues affecting the Filtering module area:IO Issues affecting the IO module area:Registration Issues affecting the Registration module labels Feb 12, 2026
Copy link
Contributor

@N-Dekker N-Dekker left a 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...

@hjmjohnson
Copy link
Member Author

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...

@N-Dekker

This PR was intended to take the first step towards some loose best-practices conventions scattered about stackoverflow/reddit/other sources:

  • Never use 'char' unless explicitly desire to work with old API's or intending characters (i.e. ASCII). The 'char' type has a different meaning based on compiler settings or platform defaults.
  • Allow 'unsigned char' and 'signed char' when the intent is bytes (i.e., for bit encodings, or enumerations).
  • Prefer 'uint8_t' and 'int8_t' when the data storage is intended to have numerical properties (addition, subtraction etc...)

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.

@N-Dekker
Copy link
Contributor

Thanks for explaining, Hans.

  • Allow 'unsigned char' and 'signed char' when the intent is bytes (i.e., for bit encodings, or enumerations).

When the intent is just raw bytes, it might be preferable to use std::byte, as introduced with C++17 😇

@hjmjohnson hjmjohnson merged commit c78ee79 into main Feb 12, 2026
18 of 19 checks passed
@hjmjohnson hjmjohnson deleted the replace-char-with-int8_t branch February 12, 2026 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:Bridge Issues affecting the Bridge module area:Core Issues affecting the Core module area:Filtering Issues affecting the Filtering module area:IO Issues affecting the IO module area:Registration Issues affecting the Registration module type:Enhancement Improvement of existing methods or implementation type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants