jeb Posted April 13, 2007 Report Share Posted April 13, 2007 hello,i have a c question :i have a global array : unsigned char test[2][2];each time a certain button is pressed, i want to reset my array to the default array {{1,2},{2,2}}(this is just a 2*2 example, the array in my code is much bigger).int this case the following line doesn't work :test = {{1,2},{2,2}};i don't want to use a loop for this !do i have to use pointers ?thanxjeb Quote Link to comment Share on other sites More sharing options...
stryd_one Posted April 13, 2007 Report Share Posted April 13, 2007 I've read something about sdcc wanting brackets around every entry, maybe try this:test = {{{1},{2}},{{2},{2}}};Wow that's ugly! Quote Link to comment Share on other sites More sharing options...
jeb Posted April 13, 2007 Author Report Share Posted April 13, 2007 hello,no the brackets solution doesn't work !the problem is maybe that i want to redefine the values of an array which has already been defined.should i use pointers ?for example if i have a global variable ://// unsigned char test [3];the use of this, in a function ://// test = {8, 8, 8};gives :syntax error: token -> '{' ; column 9thanx in advance! Quote Link to comment Share on other sites More sharing options...
Lall Posted April 13, 2007 Report Share Posted April 13, 2007 Hello,I think that this way of intializing arrays is only valid when it's used while defining the variable. I don't think it's allowed to be used as this in the body of a function.You could indeed use a pointer instead, have a collection of the constant tables as you shown and have the pointer to point on one of the constant tables.Othewise, you can also define constant tables and use a memcpy like function to copy the constant table within your array.Best regards,Lall Quote Link to comment Share on other sites More sharing options...
stryd_one Posted April 13, 2007 Report Share Posted April 13, 2007 I think that this way of initializing arrays is only valid when it's used while defining the variable. I don't think it's allowed to be used as this in the body of a function.I had a feeling that was it, but I didn't have the confidence to say it hehehehHey jeb what are you putting in this array? There might be a quick way, depending on what is going in there... Quote Link to comment Share on other sites More sharing options...
Shadyman Posted December 11, 2007 Report Share Posted December 11, 2007 AFAIK, You could always cheat...test[0] = {1,2};test[1] = {2,2}; ;D Quote Link to comment Share on other sites More sharing options...
stryd_one Posted December 13, 2007 Report Share Posted December 13, 2007 If that compiles with SDCC PIC16 port, I'll give you a lollypop. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.