Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Post History
Is uint8_t guaranteed to be a character type if it exists? Will using a uint8_t* to examine bytes of an object cause violation of the strict aliasing rule? Is the following legal code: #include &l...
#2: Post edited
- Is `uint8_t` guaranteed to be a character type if it exists? Will using a `uint8_t*` to examine bytes of an object cause violation of the strict aliasing rule? Is the following legal code:
- ```
- #include <cstdint>
- #include <cstdio>
- #include <string>
- int main() {
- std::string str{"Hello"};
- std::uint8_t* p = reinterpret_cast<std::uint8_t*>(&str);
for (int i = 0; i < sizeof str; ++i) {- std::printf("%d\n", *p++);
- }
- }
- ```
- Is `uint8_t` guaranteed to be a character type if it exists? Will using a `uint8_t*` to examine bytes of an object cause violation of the strict aliasing rule? Is the following legal code:
- ```
- #include <cstddef>
- #include <cstdint>
- #include <cstdio>
- #include <string>
- int main() {
- std::string str{"Hello"};
- std::uint8_t* p = reinterpret_cast<std::uint8_t*>(&str);
- for (std::size_t i = 0; i < sizeof str; ++i) {
- std::printf("%d\n", *p++);
- }
- }
- ```
#1: Initial revision
Is `uint8_t` always an alias for a character type if it exists?
Is `uint8_t` guaranteed to be a character type if it exists? Will using a `uint8_t*` to examine bytes of an object cause violation of the strict aliasing rule? Is the following legal code: ``` #include <cstdint> #include <cstdio> #include <string> int main() { std::string str{"Hello"}; std::uint8_t* p = reinterpret_cast<std::uint8_t*>(&str); for (int i = 0; i < sizeof str; ++i) { std::printf("%d\n", *p++); } } ```