jeb Posted April 13, 2007 Report 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
stryd_one Posted April 13, 2007 Report 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!
jeb Posted April 13, 2007 Author Report 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!
Lall Posted April 13, 2007 Report 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
stryd_one Posted April 13, 2007 Report 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...
Shadyman Posted December 11, 2007 Report Posted December 11, 2007 AFAIK, You could always cheat...test[0] = {1,2};test[1] = {2,2}; ;D
stryd_one Posted December 13, 2007 Report Posted December 13, 2007 If that compiles with SDCC PIC16 port, I'll give you a lollypop.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now