C ++ memory platform for static vs member function static vs member function static

Consideration of 3 different static arrays in the Class.cpp file:

static char array0[8];

/*static*/ char Class::s_array1[8]; //static declared in Header Class.h

void Class::DoStuff()
{
    static char f_array2[8];
}

Is it clearly defined whether 3 arrays will be adjacent in memory relative to each other and in what order? (Or it depends on the compiler / platform)

+4
source share
2 answers

Arrays are always contiguous in memory, but they are not defined where they will be related to each other.

+2
source

It completely depends on the compiler and platform. In case it works on the Linux platform, you can guess that these arrays will be in the .bss section.

Obviously, each array is offset in memory. It is necessary.

+2

Source: https://habr.com/ru/post/1537783/


All Articles