tags:

views:

330

answers:

2

I'm trying to figure out what the compiler doesn't like about this:

enum { COLS = 10 };
void process_row( int arr2d[][COLS], int row, int arr[], int pickrow);
...
int a2d[][COLS] = { {1,2,3}, {4,5,6}, {7,8,9} };

I get a error: ISO C90 forbids mixed declarations and code on the a2d[][COLS] declaration. I tried looking up the error but I wasn't able to understand what is being mixed.

In the above, it should be creating

1 2 3 0 0 0 0 0 0 0
4 5 6 0 0 0 0 0 0 0
7 8 9 0 0 0 0 0 0 0

I thought it might be the symbolic constant, but it seems to be accepting it fine as a function parameter... what am I missing here?

This is compiled to conform with ansi-C.

+2  A: 

It looks fine to me, and I got no such warning. What compiler and flags did you use? For reference, I used:

gcc -c foo.c -Wall -ansi -pedantic -W -Wextra

Where foo.c contained:

enum { COLS = 10 };
void process_row( int arr2d[][COLS], int row, int arr[], int pickrow);
int a2d[][COLS] = { {1,2,3}, {4,5,6}, {7,8,9} };
Chris Young
This is compiled with gcc -Wall -ansi -pedantic-errors -Werror work2.c work2.xI get this error:work2.c:24: error: ISO C90 forbids mixed declarations and codeWhere 24 is the a2d[][COLS]
zxcv
It looks like the stripped down version works fine... hmm, the error must be somewhere else. I'll look around some more and see bout closing this question since the issue looks to be somewhere else. Thanks for you help.
zxcv
+1  A: 

Works for me, too. Does just the stripped down foo.c shown by Chris Young work? Do you possibly have a COLS macro defined?

ysth
The stripped down version seems to work fine... I must be doing something else wrong.
zxcv