SCC 3.88 fails to compile the following code with errors reported of 'Can't complete RBP relative address' when accessing global multi-dimensional arrays for 64 bit compilation. There are two workarounds, also shown in the code snippet which compile OK.
int two_dimensional_array[4][3];
void initialise_array() {
for (int i = 0; i < 4; i++) {
two_dimensional_array[i][0] = 0;
two_dimensional_array[i][1] = 0;
two_dimensional_array[i][2] = 0;
}
}
// Workaround by gaining a pointer to the array row, less readable.
void initialise_array_workaround() {
for (int i = 0; i < 4; i++) {
int *array_row = two_dimensional_array[i];
array_row[0] = 0;
array_row[1] = 0;
array_row[2] = 0;
}
}
// Workaround to pass global as a parameter, better practice anyway.
void alt_initialise_array(int x_dimensional_array[4][3]) {
for (int i = 0; i < 4; i++) {
x_dimensional_array[i][0] = 0;
x_dimensional_array[i][1] = 0;
x_dimensional_array[i][2] = 0;
}
}
int main()
{
alt_initialise_array(two_dimensional_array);
return 0;
}
The compilation command and compiler output;
>scc arrayrepro /win/64
[Silverfrost SCC/WIN32 Ver 3.88 Copyright (c) Silverfrost Ltd 2017]
0011 void initialise_array_workaround() {
*** Can't complete RBP relative address
*** Can't complete RBP relative address
*** Can't complete RBP relative address
3 ERRORS [<ARRAYREPRO> SCC/WIN32 Ver 3.88]
*** Compilation failed