4

Considering 3 different static arrays in some 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 the 3 arrays will be contiguous in memory relative to each other, and in which order? (Or does it depend on the compiler/platform)

2
  • 1
    You can, by getting their memory addresses, and compare/sort them ... but what is the goal ? what do you try to do ? Commented Apr 23, 2014 at 20:53
  • I mean is it predictable, or does it depend on compiler /platform etc? Commented Apr 23, 2014 at 20:57

2 Answers 2

2

Arrays are always contiguous in memory, but it is not defined where they will end up relative to each other.

Sign up to request clarification or add additional context in comments.

Comments

2

This is fully compiler and platform dependent. In the case it runs on a Linux platform, you can guess that these arrays will be in the .bss section.

Obviously, each array is contiguous in memory. This is mandatory.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.