void playWithThePixels(void* p, int depth, int pitch, int width, int height);
typedef unsigned char Pixel[4];
std::vector<Pixel[1600]> screen(900);
playWithThePixels(screen.data(), 32, 1600, 1600, 900);
return 0;
Both the elements of a C array and std::vector
is guaranteed to be contiguous, so screen
should be laid out contiguously in memory.
I know accessing the array elements out of bounds is undefined behaviour, but how about when reading through a pointer, such as in the example code?
Or what if you do
std::cout << screen[0][10000][0];
? Is this defined behaviour? I'm obviously accessing an allocated area.
Does reading the array elements whether directly or indirectly through a pointer make a difference?