External Issue: Unable to pass const arrays to external routines

18790, "twesterhout", "Unable to pass const arrays to external routines", "2021-12-02T23:17:28Z"

Summary of Problem

Arrays declared as const cannot be passed to C functions via c_ptrTo. Having such functionality feels natural since C routines can expect const pointers and Chapel is const-correct.

Currently, Chapel fails with the following error message:

chpl -o error error.chpl
error.chpl:5: In function 'main':
error.chpl:9: error: const actual is passed to 'ref' formal 'arr' of c_ptrTo()
note: to formal of type [domain(1,int(64),false)] real(64)

Steps to Reproduce

Source Code:

use CPtr;

proc external(arg : c_ptr(real)) { }

proc main()
{
  const x = [1.1, 2.2, 3.3];
  var y = x;
  external(c_ptrTo(x)); // fails
  external(c_ptrTo(y)); // works
}

Compile command:

chpl -o error error.chpl

Configuration Information

  • Output of chpl --version: 1.25.0