Search code examples
c++arraysicc

Weird compilation error: catastrophic error: section length mismatch in array expression compilation aborted for shocktube.c


I am facing trouble in compiling a simple piece of code. Following are the details:

Variable declaration:

double q_old[3][N], q_new[3][N], u[3][N], flux[3][N+1], fl[3][N+1], fr[3][N+1];

The following line seems to be the source of error:

fl[0][1:N+1] = u[1][0:N]*u[0][0:N]; // this does not work
fl[0][1:N] = u[1][0:N]*u[0][0:N]; // this works

The error:

shocktube.c(47): catastrophic error: section length mismatch in array expression
compilation aborted for shocktube.c (code 1)

I am using intel icpc compiler. The first statement does not work but the second does, which is really weird because AFAIK the size of the LHS array in the first statement will be N(index varying from 1 to N) and size of RHS should also be N(0 to N-1), while in the second statement size of LHS is N-1.

Thanks,


Solution

  • The Intel array section notation is [start:length], not [start:end]. Therefore, this line

    fl[0][1:N+1] = u[1][0:N]*u[0][0:N]; // this does not work
    

    is invalid because you are indexing past the end of the array (specifically, you are asking for indices [1, N+2) in the fl array, whose last dimension only has N+1 elements).

    The error probably should be a little gentler ("catastrophic" is not a term I'd apply to a user error), but this is ultimately not the compiler's fault.