gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

C/C++ > parse error?

#75738 - deltree - Wed Mar 15, 2006 5:09 pm

hi,
I've a piece of code where the compiler detects a parse error:
what is the correct syntax ? (it's the beginning of the program)

Code:
typedef struct Blocks
{
      int  pos; //rotating
      char shape[16][4]; //object shape in its 4 positions
} BLOCKS;
BLOCKS block1;
block1.shape[16][4]=
{
{'.','X','.','.',    '.','.','.','.',    '.','X','.','.',     '.','.','.','.'},
{'.','X','.','.',    'X','X','X','X',    '.','X','.','.',     'X','X','X','X'},
{'.','X','.','.',    '.','.','.','.',    '.','X','.','.',     '.','.','.','.'},
{'.','X','.','.',    '.','.','.','.',    '.','X','.','.',     '.','.','.','.'}
}


if I remove this part:
Code:
block1.shape[16][4]=
{
{'.','X','.','.',    '.','.','.','.',    '.','X','.','.',     '.','.','.','.'},
{'.','X','.','.',    'X','X','X','X',    '.','X','.','.',     'X','X','X','X'},
{'.','X','.','.',    '.','.','.','.',    '.','X','.','.',     '.','.','.','.'},
{'.','X','.','.',    '.','.','.','.',    '.','X','.','.',     '.','.','.','.'}
}

then , it works fine...

#75740 - kusma - Wed Mar 15, 2006 5:30 pm

what you're doing is simply not allowed... try this instead

Code:
typedef struct Blocks
{
      int  pos; //rotating
      char shape[4][16]; //object shape in its 4 positions
} BLOCKS;

BLOCKS block1 =
{
   0,
   {
      {'.','X','.','.',    '.','.','.','.',    '.','X','.','.',     '.','.','.','.'},
      {'.','X','.','.',    'X','X','X','X',    '.','X','.','.',     'X','X','X','X'},
      {'.','X','.','.',    '.','.','.','.',    '.','X','.','.',     '.','.','.','.'},
      {'.','X','.','.',    '.','.','.','.',    '.','X','.','.',     '.','.','.','.'}
   }
};

#75741 - deltree - Wed Mar 15, 2006 5:42 pm

I'm quite new to C, and I don't know much about structures:

do I have to initialise the full struct everytime I need to change one element ?

#75751 - deltree - Wed Mar 15, 2006 6:45 pm

nevermind, I just understood my mistake.