Created
June 14, 2021 19:05
-
-
Save dsh0005/21e604b6478d653e94fc752282d97c88 to your computer and use it in GitHub Desktop.
C++ vector ouroboros
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <vector> | |
#include <stdint.h> | |
#include <inttypes.h> | |
#include <stdio.h> | |
int main(int argc, char **argv){ | |
(void)argc; | |
(void)argv; | |
std::vector<uint8_t> *b; | |
{ | |
std::vector<uint8_t> a(sizeof(a)); | |
b = new(a.data()) std::vector<uint8_t>(); | |
std::swap(a, *b); | |
} | |
printf("b = %p\n", b); | |
printf("b->size() = %zu\n", b->size()); | |
for(size_t i = 0; i < b->size(); i++){ | |
printf("(*b)[%zu] = %" PRIx8 "\n", i, (*b)[i]); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment