Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstddef>
- void f1()
- {
- std::cout << "byte[] and byte* arithmetic" << std::endl;
- std::byte x[5];
- std::byte* ptr = x;
- for (int c = 0; c < 5; c++)
- std::cout << &x[c] << ",";
- std::cout << " <- bytes" << std::endl;
- for (int c = 0; c < 5; c++)
- std::cout << ptr+c << ",";
- std::cout << " <- bytes" << std::endl << std::endl;
- }
- void f2()
- {
- std::cout << "int[] and byte* arithmetic (aliasing)" << std::endl;
- int x[5];
- std::byte* ptr = reinterpret_cast<std::byte*>(x);
- for (int c = 0; c < 5; c++)
- std::cout << &x[c] << ",";
- std::cout << " <- ints" << std::endl;
- for (int c = 0; c < 5; c++)
- std::cout << ptr+c << ",";
- std::cout << " <- bytes" << std::endl << std::endl;
- }
- int main()
- {
- f1();
- f2();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement