3
 ATTRIBUTES*  addRelation(char*,char*,ATTRIBUTES*);
 void nattr(ATTRIBUTES*);
 void tuplelen(ATTRIBUTES*);
 void infattr(char*,ATTRIBUTES*);
 void addValues(ATTRIBUTES*,char*);
 int count(VALUES*);
 void project(ATTRIBUTES*,char*);
 void select(char*,char*,char*,ATTRIBUTES*);
 int inStringArray(char*[][],int,char*);

I keep getting this error and I'm confused if I include a value in the Array it will make my program wrong ?

prototypes.h:9:1: error: array type has incomplete element type

prototypes.h:7:24: error: expected ')' before '*' token

I also have this error and yet my syntax is correct. Am I not compiling this header file correctly? I have been using gcc

7
  • compiling this header file correctly .. how? Commented Mar 27, 2015 at 7:18
  • I'm doing a makefile so I have separately compiled all my other files and this is the only giving me trouble. I have compiled it gcc prototypes.h and even if I make the program it shows this error so it is this header file Commented Mar 27, 2015 at 7:30
  • You have to provide the second dimension in int inStringArray(char*[][],int,char*);. Commented Mar 27, 2015 at 7:47
  • possible duplicate of GCC: array type has incomplete element type Commented Mar 27, 2015 at 7:47
  • what dimension that's my problem ? I've searched through the error and can't see where I went wrong. I just wanted to create the array .. if that makes sense . I'm not sure if I'm clarifying sorry I'm new to c and that's why I'm asking Commented Mar 27, 2015 at 7:51

1 Answer 1

1

An error like this is typically caused by a missing (full) declaration. In other words: One of your types is known due to a forward declaration, but the compiler doesn't know the actual structure of that type (which makes it impossible to know the length of that array or one of its elements).

Something like the following should cause the very same error:

struct Data;

Data myData[50]; // The compiler doesn't know how much data is needed

To solve this issue, you have to include the proper header file or add a full declaration (make sure to not duplicate definitions):

struct Data; // This line is now obsolete in this simple example

struct Data {
    int someInteger;
};

Data myData[50]; // The compiler now knows this is essentially 50 integers (+padding)

Didn't notice that it's not just complaining about incomplete type, but incomplete element type.

This essentially means that C++ isn't able to determine the size of a multidimensional array.

If you'd like to define or pass an n-dimensional array, you have to keep in mind that you're allowed only one dimension of variable length (since the compiler won't be able to determine the correct size otherwise). In short, there must only be one occurrence of [] at most.

Here are some examples:

void doSomething(int args[]) {
    // 1 dimension, every element is the length of one integer
    args[0]; // this is the first integer
    args[1]; // this is the second integer (offset is args + sizeof(int))
}

void doSomething(int args[][2]) {
    // 2 dimensions, every element is the length of two integers
    args[0]; // this is the first set of integers
    args[1]; // this is the second set (offset is args + sizeof(int[2]))
}

void doSomething(int args[][]) {
    // 2 dimensions, no idea how long an element is
    args[0]; // this is the first set of integers
    args[1]; // this is the second set (offset is args + sizeof(int[])... oops? how long is that?)
}

As a workaround, you can just pass pointers and hide the fact that you've got an array (since the length of pointers is known). Only downside to this is the fact that the compiler will no longer know that you're indeed passing an array rather than a single value (by reference).

void doSomething(int args*[]) {
    // 2 dimensions, set of integers
    args[0]; // this is the first set of integers
    args[1]; // this is the second set (offset is args + sizeof(int*))
}

So going back to your actual problem:

Simply replace the line

int inStringArray(char*[][],int,char*);

with

int inStringArray(char**[],int,char*);

Just keep in mind you might have to update other portions of your code as well and you'll have to be careful in case you're passing that array somewhere (e.g. freeing it using delete).

Sign up to request clarification or add additional context in comments.

2 Comments

but I don't have a struct . the error is relating to this line: int inStringArray(char*[][],int,char*);
@AsheMendez Which error is that? The line 7 message or line 9? I guess it is the line 9 one? Updating my answer...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.