passing 2d array as argument

Hello.

I am trying to do what seem to be simple task- I have an 2d array
and i pass it as argument to a function [c++ code].

Array in main:
1
2
3
  #define Words_per_Channel  30
#define Rx_num  30
u32 Recv_Array[Rx_num][Words_per_Channel];


function definition in some header file:

1
2
3
4
5
6

int ArincResultsTest(u32 Recv_Array[Rx_num][Words_per_Channel]){

...

}



function call in main:
1
2
3
4

 ArincResultsTest(Recv_Array);




I got errors in function call:

cannot convert 'u32 (*)[30]' {aka 'unsigned int (*)[30]'} to 'u32* (*)[30]' {aka 'unsigned int* (*)[30]'}

Why it is not possible to call this function like we do with 1d array?

Any help will be appreciated.
Last edited on
Works for me.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$ cat foo.cpp
typedef unsigned int u32;

#define Words_per_Channel  30
#define Rx_num  30
u32 Recv_Array[Rx_num][Words_per_Channel];

int ArincResultsTest(u32 Recv_Array[Rx_num][Words_per_Channel]){
    return 0;
}

int main ( ) {
    ArincResultsTest(Recv_Array);
}
$ g++ foo.cpp


> cannot convert 'u32 (*)[30]' {aka 'unsigned int (*)[30]'} to 'u32* (*)[30]' {aka 'unsigned int* (*)[30]'}
Check what you actually wrote.
Somewhere it seems to be expecting a 2D array of u32 pointers, not a 2D array of u32.

Random line snippets of what you think you have are no substitute for http://www.sscce.org/
It doesn't take much to make a program to prove/disprove your point.

I have those sources:
foo.h - decleration of functions in foo.cpp
foo.cpp - this contain #define foo.h

ArincResultsTest definition is in foo.cpp. and i call this function from another function in foo.cpp

I just moved ArincResultsTest function declaration from foo.h
to foo.cpp and now it is compiling.

I wonder what is the difference now?

> I wonder what is the difference now?
Dunno, I wasn't watching you edit the files.

https://git-scm.com/
If you don't have something like this to manage your programming, you need it.
git add and git commit after every change that works.
git diff for say comparing what worked with what broke.
git branch for when a change is experimental, or takes some time.

There's a lot of tools in that particular toolbox, but with those few commands you can get something useful out of it.

The last thing you want is to have a single body of code that you've worked on for months, only for you to then make some change that breaks it and have no idea what you did to break it.
Topic archived. No new replies allowed.