Multidimensional Arrays in a function prototype

This is a discussion on Multidimensional Arrays in a function prototype within the C Programming forums, part of the General Programming Boards category; Hello, I received an assignment from my software engineering course that requires me to update and work on a program ...

  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    1

    Multidimensional Arrays in a function prototype

    Hello,

    I received an assignment from my software engineering course that requires me to update and work on a program that's been in the works since the very late 90's. I decided to compile the project to see if there were any errors; sure enough, I got a mess of them. I have been able to iron out some of the errors, but there is an issue with multidimensional arrays in the prototypes of these functions in a header file.

    Here's an example of some of the functions in this header file:

    Code:
    int MatrixMultChecker(double [][], int , int ,
                          double [][], int , int ,
                          double [][], int , int );
    
    void MatrixMultCorrector(double [][], int, int,
                            double [][], int, int,
                            double [][], int, int);
    
    int CompareMatrices(double [][], int, int,
                        double [][], int, int);
    For each instance of a multidimensional array, the compiler spits out the following error:

    Code:
    ./include/matrix.h:7: error: array type has incomplete element type
    I've been checking resource sites for C (normally I program in C++, but this is a very old project), but everything I find seems to line up with the format for multidimensional arrays. Does anyone see something obvious here that I'm just not getting?

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    You either need better resource sites or better eyes. When they say "only the first size can be omitted" they mean that only the first number can be omitted. You have to give all the other sizes in the prototype. Note well that this is exactly the same in C++ also.

  3. #3
    Registered User
    Join Date
    Sep 2009
    Location
    USA
    Posts
    63
    Quote Originally Posted by Enanito01478 View Post
    Hello,

    I received an assignment from my software engineering course that requires me to update and work on a program that's been in the works since the very late 90's. I decided to compile the project to see if there were any errors; sure enough, I got a mess of them. I have been able to iron out some of the errors, but there is an issue with multidimensional arrays in the prototypes of these functions in a header file.

    Here's an example of some of the functions in this header file:

    Code:
    int MatrixMultChecker(double [][], int , int ,
                          double [][], int , int ,
                          double [][], int , int );
    
    void MatrixMultCorrector(double [][], int, int,
                            double [][], int, int,
                            double [][], int, int);
    
    int CompareMatrices(double [][], int, int,
                        double [][], int, int);
    For each instance of a multidimensional array, the compiler spits out the following error:

    Code:
    ./include/matrix.h:7: error: array type has incomplete element type
    I've been checking resource sites for C (normally I program in C++, but this is a very old project), but everything I find seems to line up with the format for multidimensional arrays. Does anyone see something obvious here that I'm just not getting?
    so

    Code:
    int MatrixMultChecker(double [][], int , int ,
                          double [][], int , int ,
                          double [][], int , int );
    
    void MatrixMultCorrector(double [][], int, int,
                            double [][], int, int,
                            double [][], int, int);
    
    int CompareMatrices(double [][], int, int,
                        double [][], int, int);
    contains an unbounded array times. In other words, the compiler can't determine what size to expect. The general rule for passing arrays as parameters is that either specify all dimensions or only leave the leftmost dimension unbounded. All other dimensions have to be defined. Thus, you can have either

    Code:
    int MatrixMultChecker(double [size1][size2], int , int ,
                          double [size3][size4], int , int ,
                          double [size5][size6], int , int );
    .......
    or

    Code:
    int MatrixMultChecker(double [][size2], int , int ,
                          double [][size4], int , int ,
                          double [][size6], int , int );
    .......

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 05-13-2011, 08:28 AM
  2. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 02:07 AM
  3. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  4. Function prototype questions
    By Kayoss in forum C++ Programming
    Replies: 6
    Last Post: 11-30-2005, 04:27 PM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21