electro-music.com   Dedicated to experimental electro-acoustic
and electronic music
 
    Front Page  |  Radio
 |  Media  |  Forum  |  Wiki  |  Links
Forum with support of Syndicator RSS
 FAQFAQ   CalendarCalendar   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   LinksLinks
 RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in  Chat RoomChat Room 
 Forum index » DIY Hardware and Software » ChucK programming language
static arrays
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [6 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
moudi



Joined: Oct 07, 2006
Posts: 63
Location: Bern Switzerland

PostPosted: Mon Jan 08, 2007 5:10 pm    Post subject: static arrays Reply with quote  Mark this post and the followings unread

ok, here's the second one as mentioned in the thread before... Smile

i tried to use a static array in one of my public classes.
everytime i tried to write to it, my miniAudicle crashed Mad
here's also a little example...
Code:

public class crash
{
   0 => static int myint;
   [0,1,2] @=> static int myarray[];   
}

//Chuck Values to this Variables without instanciation.
//The pure integer works:
1 => crash.myint;
//This one crashs miniAudicle!!:
10 => crash.myarray[1];
//I assume it's because an array is an object and needs
//therefore the instanciation?
//Should be catched anyway... ;-)

//Btw, this crashes miniAudicle too...
[[0,1],[1,1]] @=> int testarray[3][2];


any ideas or comments about this?

regards
/moudi
Back to top
View user's profile Send private message Visit poster's website
Kassen
Janitor
Janitor


Joined: Jul 06, 2004
Posts: 7678
Location: The Hague, NL
G2 patch files: 3

PostPosted: Mon Jan 08, 2007 6:04 pm    Post subject: Reply with quote  Mark this post and the followings unread

Yeah, this needs a mail to Spencer because both are bugs.

The bottom one is simple; that's simply a case of bad syntax not being caught.

The first example is more complicated; you are right and it should work like this *but* static data isn't completely implemented yet. If you try the exact same with command-line ChucK you should get a proper error, I'm not sure why the mini let's it slide untill it's too late.

To get "real" static arrays you need to use a workaround involving asignment. Basically you define your static object inside of the class but instantiate it outside. I can dig up a example if you'd like.

_________________
Kassen
Back to top
View user's profile Send private message Send e-mail Visit poster's website
moudi



Joined: Oct 07, 2006
Posts: 63
Location: Bern Switzerland

PostPosted: Tue Jan 09, 2007 1:08 pm    Post subject: Reply with quote  Mark this post and the followings unread

Kassen wrote:
Yeah, this needs a mail to Spencer because both are bugs.

so you mean i should write it to the mailing list?

Kassen wrote:

To get "real" static arrays you need to use a workaround involving asignment. Basically you define your static object inside of the class but instantiate it outside. I can dig up a example if you'd like.

that's exactly what i already did Cool

regards
/moudi
Back to top
View user's profile Send private message Visit poster's website
spencer



Joined: Aug 16, 2006
Posts: 53
Location: northern california

PostPosted: Thu Jan 11, 2007 6:18 am    Post subject: Reply with quote  Mark this post and the followings unread

Howdy,
moudi wrote:
Code:

public class crash
{
   0 => static int myint;
   [0,1,2] @=> static int myarray[];   
}

//Chuck Values to this Variables without instanciation.
//The pure integer works:
1 => crash.myint;
//This one crashs miniAudicle!!:
10 => crash.myarray[1];


Argh! Thanks for finding this. There are still a few bugs in ChucK's array and class implementations, but I thought most of the crashing ones were under control. I'll start looking into a fix, but it sounds like you have workaround for now.

Also, both command-line chuck and miniAudicle crash on this--miniAudicle uses the exact same ChucK implementation as chuck so thats expected behavior.

moudi wrote:
Code:

//Btw, this crashes miniAudicle too...
[[0,1],[1,1]] @=> int testarray[3][2];


Hmm, I can't seem to be able to get it to crash by itself. Its not completely clear what should happen here, but I think its actually legal in terms of syntax. However, on my tests it seems that the array is zeroed out and never initialized with the new values unless the array declaration and initialization is done in two separate statements. After that ChucK treats the array like a 2x2 array, which makes some sort of sense, if one thinks of an array not as a vector of data, but a reference to an array object.
Back to top
View user's profile Send private message
ge



Joined: Aug 13, 2006
Posts: 108
Location: Palo Alto, CA

PostPosted: Thu Jan 11, 2007 8:40 am    Post subject: Re: static arrays Reply with quote  Mark this post and the followings unread

moudi wrote:
Code:

public class crash
{
   0 => static int myint;
   [0,1,2] @=> static int myarray[];   
}


This is a known bug, I believe. Currently, there are problems with directly initializing or even instantiating static members that are non-primitives (e.g. not int, float, time, dur). The workaround is to declare as reference and initialize outside:

Code:

public class X
{
    static int arr[][];
}

// initialize
new int[4][5] @=> X.arr;


Hopefully that should work...
Back to top
View user's profile Send private message Visit poster's website
moudi



Joined: Oct 07, 2006
Posts: 63
Location: Bern Switzerland

PostPosted: Mon Jan 15, 2007 3:04 pm    Post subject: Reply with quote  Mark this post and the followings unread

spencer wrote:

moudi wrote:
Code:

//Btw, this crashes miniAudicle too...
[[0,1],[1,1]] @=> int testarray[3][2];


Hmm, I can't seem to be able to get it to crash by itself. Its not completely clear what should happen here, but I think its actually legal in terms of syntax. However, on my tests it seems that the array is zeroed out and never initialized with the new values unless the array declaration and initialization is done in two separate statements. After that ChucK treats the array like a 2x2 array, which makes some sort of sense, if one thinks of an array not as a vector of data, but a reference to an array object.

do you mean that your miniaudicle survives the attack above Question
perhaps it's windows specific?
by the way: i discovered it by a simple typing mistake, it was no intention Wink

ge wrote:

Hopefully that should work...

yep, it does Smile

any news about the filterbehaviour from the other thread?
http://electro-music.com/forum/topic-15426.html&sid=9d5ff565d0fc46290fd49b980c4f9cb3
(sorry for the crossposting).

cheers
/moudi
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [6 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
 Forum index » DIY Hardware and Software » ChucK programming language
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Forum with support of Syndicator RSS
Powered by phpBB © 2001, 2005 phpBB Group
Copyright © 2003 through 2009 by electro-music.com - Conditions Of Use