Skip to content
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

Replace iox::byte_t with std::byte #1900

Closed
3 tasks done
elBoberido opened this issue Feb 15, 2023 · 2 comments · Fixed by #1909 or #2103
Closed
3 tasks done

Replace iox::byte_t with std::byte #1900

elBoberido opened this issue Feb 15, 2023 · 2 comments · Fixed by #1909 or #2103
Labels
good first issue Good for newcomers refactoring Refactor code without adding features technical debt unclean code and design flaws

Comments

@elBoberido
Copy link
Member

elBoberido commented Feb 15, 2023

Brief feature description

Currently iox::byte_t is a uint8_t. Having a distinct type like C++17 std::byte helps to prevent issues with accidentally passing a uint8_t where a iox::byte_t is expected.

Detailed information

A drop in replacement for std::byte with C++14 is not possible since the compiler does not treat an enum class byte : uint8_t {}; like an unsigned char and therefore the strict aliasing rule cannot be applied. With C++17 beside char and unsigned char also std::byte can be used. See also the Type aliasing section in reinterpret_cast.

Tasks

  • consolidate all byte_t types
  • rename iox::byte_t to iox::byte
  • use std::byte when switching to C++17
@elBoberido elBoberido added good first issue Good for newcomers refactoring Refactor code without adding features technical debt unclean code and design flaws labels Feb 15, 2023
@elfenpiff
Copy link
Contributor

@elBoberido this is a cool idea and I think we already have - maybe even multiple - definitions of that type.

Why an enum class and not a NewType?

@elBoberido
Copy link
Member Author

elBoberido commented Feb 16, 2023

@elfenpiff simple solutions for simple problems ;)

The enum class is sufficient for this since we do not want to do any arithmetic with the type. We just want something which is 1 byte large and does not do anything.

zmostafa added a commit to zmostafa/iceoryx that referenced this issue Feb 20, 2023
zmostafa added a commit to zmostafa/iceoryx that referenced this issue Feb 20, 2023
zmostafa added a commit to zmostafa/iceoryx that referenced this issue Feb 20, 2023
zmostafa added a commit to zmostafa/iceoryx that referenced this issue Feb 20, 2023
zmostafa added a commit to zmostafa/iceoryx that referenced this issue Feb 21, 2023
zmostafa added a commit to zmostafa/iceoryx that referenced this issue Feb 21, 2023
@elBoberido elBoberido changed the title Make iox::byte_t a distinct type Align iox::byte_t with std::byte Feb 21, 2023
zmostafa added a commit to zmostafa/iceoryx that referenced this issue Feb 21, 2023
zmostafa added a commit to zmostafa/iceoryx that referenced this issue Feb 21, 2023
zmostafa added a commit to zmostafa/iceoryx that referenced this issue Feb 21, 2023
zmostafa added a commit to zmostafa/iceoryx that referenced this issue Feb 27, 2023
zmostafa added a commit to zmostafa/iceoryx that referenced this issue Feb 27, 2023
@elBoberido elBoberido reopened this Feb 27, 2023
@elBoberido elBoberido changed the title Align iox::byte_t with std::byte Replace iox::byte_t with std::byte Nov 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers refactoring Refactor code without adding features technical debt unclean code and design flaws
Projects
None yet
2 participants