Errors/warnings passing int/char arrays by reference
- by Ankur Banerjee
I'm working on a program where I try to pass parameters by reference. I'm trying to pass a 2D int array and a 1D char array by reference.
Function prototype:
void foo (int* (&a)[2][2], char* (&b)[4])
Function call:
foo (a, b);
However, when I compile the code with -ansi and -Wall flags on gcc, I get the following errors:
foo.c: At top level:
error: expected ‘)’ before ‘&’ token
error: expected ‘;’, ‘,’ or ‘)’ before ‘char’
foo.c: In function ‘main’:
error: too many arguments to function ‘foo’
I've stripped out the rest of the code of my program and concentrated on the bits which throw up the errors. I've searched around on StackOverflow and tried out different ways to pass the parameters, but none of them seem to work. (I took this way of passing parameters from the discussion on StackOverflow here.)
Could you please tell me where I'm going wrong?