Thread: error: array type has incomplete element type

  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    8

    error: array type has incomplete element type

    Hi,

    I'm getting this error when I tried to compile the program in Linux platform.

    'error: array type has incomplete element type'

    It works fine in AIX and was able to successfully compile, but not in Linux.

    Here's a part of the code:
    #ifdef MAIN_PROG
    struct COMPETITOR competitor[MAX_SIZE];
    struct COMPETITOR competitor_sav[MAX_SIZE];
    .
    .
    .
    #else
    .
    .
    extern struct COMPETITOR competitor[];
    extern struct COMPETITOR competitor_sav[];
    #endif

    Any input on this? Thanks.

  2. #2
    Registered User
    Join Date
    Sep 2007
    Posts
    1,012
    Is struct COMPETITOR defined when MAIN_PROG is not? The error message is telling you that gcc doesn't know anything about a struct COMPETITOR, so it can't figure out how it would create (or index) an array of them. I can't tell you why an AIX compiler wouldn't have the same problem; but the source of the gcc error is lack of a struct definition.

  3. #3
    Registered User
    Join Date
    Oct 2010
    Posts
    8

    error: array type has incomplete element type

    Thanks cas for your response.
    What do you mean by the source of the gcc error is lack of a struct defition? If it lack of a struct definition, how it can be defined then based on the provided code? Please advise. Thanks again.

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Looks like you're trying to create an array of structs in Linux, without specifying the size of the array. Add a #define for MAX_SIZE, or provide some other suitable size for it.

    Empty squared brackets just won't work.

  5. #5
    Registered User
    Join Date
    Oct 2010
    Posts
    8

    error: array type has incomplete element type

    Thanks Adak for your response.
    Yes the MAX_SIZE has been defined in the code.

    #define MAX_SIZE 1000.

    The program has been successfully compiled in AIX, and it's working fine. However, when I tried to compile in Linux, I'm getting this error. So I'm not sure if there's a compatibility issue or whatever. Please advise. Thanks.

  6. #6
    Registered User
    Join Date
    Sep 2007
    Posts
    1,012
    Quote Originally Posted by gerger View Post
    Thanks cas for your response.
    What do you mean by the source of the gcc error is lack of a struct defition? If it lack of a struct definition, how it can be defined then based on the provided code? Please advise. Thanks again.
    How can what be defined based on the previous code? You mean when MAIN_PROG is defined? That was my entire question: does your struct get defined inside of an #ifdef MAIN_PROG block? If yes, there's your problem. If no, then it's hard to say, but you have to figure out if your struct is being defined during the build when you get the error.

    Find out where your struct definition is. Put an #error directive above it (gcc should support that). If your build does not bomb out on the line containing #error, your struct is not being defined at all:
    Code:
    #error this should be reached
    struct foo { int bar; }
    Now if the compiler sees the definition for struct foo, it will also see #error, and be forced to stop translating. If it keeps translating (compiling), that means your struct was not seen.

  7. #7
    Registered User
    Join Date
    Oct 2010
    Posts
    8

    error: array type has incomplete element type

    The struct is defined outside the MAIN_PROG.

    I am wondering why the same code has been successfully compiled in AIX and is working fine. The problem is in Linux, I'm getting the compile error in Linux.

  8. #8
    Registered User
    Join Date
    Sep 2007
    Posts
    1,012
    Quote Originally Posted by gerger View Post
    The struct is defined outside the MAIN_PROG.

    I am wondering why the same code has been successfully compiled in AIX and is working fine. The problem is in Linux, I'm getting the compile error in Linux.
    Who knows? You haven't indicated that you've tried what I've suggested. It's hard enough to debug things when you can't see code, but when you can't even tell whether what you're trying is being implemented, it becomes impossible.

  9. #9
    Nasal Demon Xupicor's Avatar
    Join Date
    Sep 2010
    Location
    Poland
    Posts
    179
    Quote Originally Posted by Adak View Post
    Looks like you're trying to create an array of structs in Linux, without specifying the size of the array. Add a #define for MAX_SIZE, or provide some other suitable size for it.

    Empty squared brackets just won't work.
    Again, did you provide a size for your arrays in those lines?
    Code:
    extern struct COMPETITOR competitor[];
    extern struct COMPETITOR competitor_sav[];
    I can't understand what those lines mean, actually.

    Maybe you want this instead?
    Code:
    extern struct COMPETITOR * competitor;
    extern struct COMPETITOR * competitor_sav;
    or
    Code:
    struct COMPETITOR competitor[MAX_SIZE];
    struct COMPETITOR competitor_sav[MAX_SIZE];
    It would help if you would give us a short complete example that works on AIX and not on Linux.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Passing Argument from incompatible pointer type
    By AmritxD in forum C Programming
    Replies: 3
    Last Post: 08-15-2010, 03:23 PM
  2. Script errors - bool unrecognized and struct issues
    By ulillillia in forum Windows Programming
    Replies: 10
    Last Post: 12-18-2006, 04:44 AM
  3. Using VC Toolkit 2003
    By Noobwaker in forum Windows Programming
    Replies: 8
    Last Post: 03-13-2006, 07:33 AM
  4. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 12:04 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM