[chuck-users] dynamic array crashes for "int ar[]" but not "int ar[0]"

Kassen signal.automatique at gmail.com
Sat Jul 28 09:42:08 EDT 2012

> Hi,

Hey George!

> array.size(int) and the '<<' operator are crashing miniAudicle (version
> 0.2.0, on Windows 7 pro).  (functionality added to chuck in,
> http://chuck.cs.princeton.edu/release/VERSIONS ).  miniAudicle tells me it's
> running chuck


> playing around a bit, I now find that if I follow what the example
> array_dynamic.ck says and replace "int ar[]" with "int ar[0]", then the code
> works.  I guess that means this isn't a bug but a meaningful difference
> between ar[] and ar[0]?  In any case, I might amend the array_dynamic.ck to
> say something like
> "float argh[0]; // must set argh[0] and not argh[]"

Well, if ChucK crashes it's a bug; ChucK should not crash if you make
a syntax error, it should catch it at parsing and inform you. It is
also not unambiguously clear to me that what you tried is actually a
error, IMHO this should be fair game, it looks natural and expressive.
I can tell you what goes wrong though.

"int ar[]" creates a reference to a array but does not instantiate it.
You'd use it in a context like this;
[1, 2, 3] @=> int ar[];

Evidently ar.size(int a) should instantiate the new array entries if a
is larger than the old size, which it'll always be for uninstantiated
arrays so I find what you tried defensible, but ChucK is also a bit
right to complain about a null-pointer as the reference doesn't point
to anything yet at that point. Syntactically it seems a bit awkward,
compared to the rest of ChucK where we don't need to care about memory
management, though it might also have uses where this kind of explicit
control is useful.

I hope that clarifies things a bit? If all of this sounded like
abracadabra; just use the one that works, that's what this comes down
to :-)


More information about the chuck-users mailing list