Is it possible to declare an array with config?

99封情书 提交于 2019-12-05 11:30:07

Is it possible to declare an array with config?

No, this is not yet supported in Chapel as of Chapel 1.16.

That said, there are ways to work around this as you demonstrate.

As an alternative work-around, you can utilize IO calls to write the input string to memory and then read it in as an array, e.g.

config type  arrType = int;
config const arrSize = 3,
             arrString = '1 2 3';

var A : [1..arrSize] arrType;

// Create a memory buffer to write in
var f = openmem();

// Create a writer on the memory buffer and write the input string
var w = f.writer();
w.writeln(arrString);
w.close();

// Create a reader on the memory buffer and read the input string as an array
var r = f.reader();
r.readln(A);
r.close();

writeln(A);

Note this requires the array size up front. I think you'd have to do some string processing like your original example to compute that on the fly.

Some resources:

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!