I'm trying to declare an object array and initialize it later in a function: Channel channels[]; initChannels(4, 16); fun void initChannels(int num, int length) { Channel ch[num] @=> channels; ... This gives a segmentation fault, and trying like this: fun void initChannels(int num, int length) { channels[num]; gives a bus error. How should this be done? Thanks always, Ollie
i think there's general problem with object array initialization. i also experienced problems with it that were solved when i declared each element of the new array as a single variable and the @=> to the array-elements. instead of obj o[4]; i had to write: obj o1; obj o2; obj o3; obj o4; obj @ o[4]; o1 @=> o[0]; o2 @=> o[1]; ... best joerg Ollie Glass wrote:
I'm trying to declare an object array and initialize it later in a function:
Channel channels[]; initChannels(4, 16);
fun void initChannels(int num, int length) { Channel ch[num] @=> channels; ...
This gives a segmentation fault, and trying like this:
fun void initChannels(int num, int length) { channels[num];
gives a bus error. How should this be done?
Thanks always,
Ollie _______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
-- http://joerg.piringer.net http://www.transacoustic-research.com http://www.iftaf.org http://www.vegetableorchestra.org/
Hi Joerg!
i also experienced problems with it that were solved when i declared each element of the new array as a single variable and the @=> to the array-elements. instead of
obj o[4];
i had to write: obj o1; obj o2; obj o3; obj o4;
obj @ o[4]; o1 @=> o[0]; o2 @=> o[1]; ...
Is the offending declaration nested inside a class or function definition? They seem to be working for me, so I suspect there might be other forces of chuck at work here. Another workaround, instead of declaring each element, you might try the new operator (though it could be subject to the same bug as above): obj @ o[4]; for( int i; i < o.cap(); i++ ) new obj @=> o[i]; Sorry for the troublesome bug. We will take a deeper look into this. If you can pinpoint a demonstrative program (short as possible) that behaves incorrectly with these issues, it would help quite a bit. Best, Ge!
hi Ge, i was trying to reproduce the error and was not quite successful. but i run into the following problem: i am @=>ing a new object to an array and then trying to spork a member function of that object array. i get an array out of bounds exception when sporking. the assignment works fine. see the attached script... i think this is somehow related to the earlier problem. best joerg Ge Wang wrote:
Hi Joerg!
i also experienced problems with it that were solved when i declared each element of the new array as a single variable and the @=> to the array-elements. instead of
obj o[4];
i had to write: obj o1; obj o2; obj o3; obj o4;
obj @ o[4]; o1 @=> o[0]; o2 @=> o[1]; ...
Is the offending declaration nested inside a class or function definition? They seem to be working for me, so I suspect there might be other forces of chuck at work here.
Another workaround, instead of declaring each element, you might try the new operator (though it could be subject to the same bug as above):
obj @ o[4]; for( int i; i < o.cap(); i++ ) new obj @=> o[i];
Sorry for the troublesome bug. We will take a deeper look into this. If you can pinpoint a demonstrative program (short as possible) that behaves incorrectly with these issues, it would help quite a bit.
Best, Ge!
_______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
-- http://joerg.piringer.net http://www.transacoustic-research.com http://www.iftaf.org http://www.vegetableorchestra.org/ 1 => int newnum; class Loop { newnum => int num; newnum++; function void playLoop() { while(true) { <<< num >>>; 500::ms => now; } } } <<< "starting loops..." >>>; 4 => int maxloop; Loop @ loop[maxloop]; int lnr; for(0 => lnr; lnr < loop.cap(); lnr++) { <<< "new loop",lnr >>>; new Loop @=> loop[lnr]; // uncomment mr. spork to see the weirdness //spork ~ loop[lnr].playLoop(); } <<< "loops started" >>>; while(true) { 10::ms => now; }
Hi Joerg,
i was trying to reproduce the error and was not quite successful. but i run into the following problem: i am @=>ing a new object to an array and then trying to spork a member function of that object array.
sporking non-static member functions is another known bug. It causes incorrect behavior. Here is a workaround: https://lists.cs.princeton.edu/pipermail/chuck-users/2006-June/ 000714.html It's not pretty, but it's one way to essentially spork a member function. Sorry about all the egregious hacks. We are onto these bugs and will (ex)terminate them! Best Ge!
ah, thanks! next time i'll have a look before i post things like that. best jörg Ge Wang wrote:
Hi Joerg,
i was trying to reproduce the error and was not quite successful. but i run into the following problem: i am @=>ing a new object to an array and then trying to spork a member function of that object array.
sporking non-static member functions is another known bug. It causes incorrect behavior. Here is a workaround:
https://lists.cs.princeton.edu/pipermail/chuck-users/2006-June/ 000714.html
It's not pretty, but it's one way to essentially spork a member function. Sorry about all the egregious hacks. We are onto these bugs and will (ex)terminate them!
Best Ge!
_______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
-- http://joerg.piringer.net http://www.transacoustic-research.com http://www.iftaf.org http://www.vegetableorchestra.org/
Hi Ollie! Which platform are you running? Also, can you include the greater program, or more of the context? I can't seem to reproduce the crash on OS X using the following code: --- public class X { int hi; fun void boo() { <<< hi >>>; } } class Y { X xs[]; init( 4 ); fun void init( int num ) { X x[num] @=> xs; for( int i; i < num; i++ ) i => xs[i].hi; } } // make y Y y; // print for( int i; i < y.xs.cap(); i++ ) y.xs[i].boo(); --- It may be a chuck bug elsewhere... Best, Ge! On Jul 13, 2006, at 12:11 PM, Ollie Glass wrote:
I'm trying to declare an object array and initialize it later in a function:
Channel channels[]; initChannels(4, 16);
fun void initChannels(int num, int length) { Channel ch[num] @=> channels; ...
This gives a segmentation fault, and trying like this:
fun void initChannels(int num, int length) { channels[num];
gives a bus error. How should this be done?
Thanks always,
Ollie _______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
participants (3)
-
Ge Wang
-
joerg piringer
-
Ollie Glass