Most C compilers allow accessing an array declared extern
, which has indeterminate bounds, like this:
extern int external_array[];
int
array_get (long int index)
{
return external_array[index];
}
The definition of external_array could reside in a different translation unit and look like this:
int external_array[3] = { 1, 2, 3 };
The question is what happens if this separate definition is changed to this:
int external_array[4] = { 1, 2, 3, 4 };
Or this:
int external_array[2] = { 1, 2 };
Does either change preserve the binary interface (assuming that there is a mechanism that allows the application to determine the size of the array at run time)?
Curiously, the answer is that on many architectures, increasing the array size breaks binary interface (ABI) compatibility. Decreasing the array size may also cause compatibility problems. We’ll look more closely at ABI compatibility in this article and explain how to avoid problems.
Continue reading “How C array sizes become part of the binary interface of a library”