Help w/ "incomplete type" error

Discussion in 'C Programming' started by kj, Jul 6, 2005.

  1. kj

    kj Guest

    Hi. I'm trying to compile some software from source, and I'm
    getting an error I can't figure out. The error in question is

    key_events.h:38: field `id' has incomplete type

    and the lines corresponding to the error are:

    struct kb_event_id_s
    {
    char name[16];
    int number;
    };
    typedef struct kb_event_id_s kb_event_id_t;

    struct kb_event_map_s {
    char prefix[8];
    const kb_event_id_t id[];
    };
    typedef struct kb_event_map_s kb_event_map_t;


    I can't spot the error. Can someone give me a hand?

    Thanks!

    kj

    --
    NOTE: In my address everything before the first period is backwards;
    and the last period, and everything after it, should be discarded.
     
    kj, Jul 6, 2005
    #1
    1. Advertising

  2. kj

    Richard Bos Guest

    kj <> wrote:

    > Hi. I'm trying to compile some software from source, and I'm
    > getting an error I can't figure out. The error in question is
    >
    > key_events.h:38: field `id' has incomplete type


    > struct kb_event_map_s {
    > char prefix[8];
    > const kb_event_id_t id[];
    > };


    > I can't spot the error.


    The error is precisely what the error message told you: the field called
    id, in the struct called kb_event_map_s, has incomplete type. Variable-
    length arrays are valid only in C99, and you're probably using a C89
    compiler, so you can't do this. You must give id some specific size. If
    you need a variable-length array, you can either find a C99 compiler, or
    make id a pointer and use malloc().

    Richard
     
    Richard Bos, Jul 6, 2005
    #2
    1. Advertising

  3. kj

    Suman Guest

    kj wrote:
    > Hi. I'm trying to compile some software from source, and I'm
    > getting an error I can't figure out. The error in question is
    >
    > key_events.h:38: field `id' has incomplete type
    >
    > and the lines corresponding to the error are:
    >
    > struct kb_event_id_s
    > {
    > char name[16];
    > int number;
    > };
    > typedef struct kb_event_id_s kb_event_id_t;
    >
    > struct kb_event_map_s {
    > char prefix[8];
    > const kb_event_id_t id[];

    ^^
    The error is due to the fact that you have not specified
    the number of elements that id can/should hold. The compiler is at a
    loss.
    Either initialise the kb_event_id_t array with specific
    objects or specify some value between [],
    that is evaluated to some integer at compile time. Of course there
    are VLA's in C99 but the above should be good enough to get started.
    > };
    > typedef struct kb_event_map_s kb_event_map_t;
    >
    >
    > I can't spot the error. Can someone give me a hand?
    >
    > Thanks!
    >
    > kj
    >
    > --
    > NOTE: In my address everything before the first period is backwards;
    > and the last period, and everything after it, should be discarded.
     
    Suman, Jul 6, 2005
    #3
  4. kj

    Me Guest

    > key_events.h:38: field `id' has incomplete type
    >
    > struct kb_event_map_s {
    > char prefix[8];
    > const kb_event_id_t id[];
    > };
    >
    >
    > I can't spot the error. Can someone give me a hand?


    Your compiler doesn't support C99's flexible array members. Some
    pre-C99 compilers implemented this as id[0], if that fails you can
    always try the "struct hack" trick (not legal but works well in
    practice).
     
    Me, Jul 6, 2005
    #4
  5. On 6 Jul 2005 05:55:17 -0700, "Suman" <> wrote:

    > kj wrote:

    <snip>
    > > key_events.h:38: field `id' has incomplete type

    <snip>
    > > struct kb_event_map_s {
    > > char prefix[8];
    > > const kb_event_id_t id[];

    > ^^
    > The error is due to the fact that you have not specified
    > the number of elements that id can/should hold. The compiler is at a
    > loss.


    For a C90 compiler, as others have noted, true.

    > Either initialise the kb_event_id_t array with specific
    > objects or specify some value between [],
    > that is evaluated to some integer at compile time. Of course there
    > are VLA's in C99 but the above should be good enough to get started.


    All three of these are only applicable to a 'top-level' object, not a
    field in a struct which is obviously the case here and as the OP's
    quoted error message confirms.

    - David.Thompson1 at worldnet.att.net
     
    Dave Thompson, Jul 11, 2005
    #5
  6. kj

    Suman Guest

    Dave Thompson wrote:
    [snip]...
    > > Either initialise the kb_event_id_t array with specific
    > > objects or specify some value between [],
    > > that is evaluated to some integer at compile time. Of course there
    > > are VLA's in C99 but the above should be good enough to get started.

    >
    > All three of these are only applicable to a 'top-level' object, not a
    > field in a struct which is obviously the case here and as the OP's
    > quoted error message confirms.
    >

    My mistake.
     
    Suman, Jul 11, 2005
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Lou Pecora
    Replies:
    6
    Views:
    68,458
    santoshreddy3
    Jul 7, 2011
  2. Halid Umar A M

    Error: field has incomplete type

    Halid Umar A M, Apr 27, 2006, in forum: C Programming
    Replies:
    2
    Views:
    778
    David Resnick
    Apr 27, 2006
  3. gk245
    Replies:
    2
    Views:
    1,253
    Christopher Benson-Manica
    May 6, 2006
  4. John Sasso
    Replies:
    3
    Views:
    869
    SM Ryan
    Jul 16, 2006
  5. Replies:
    13
    Views:
    841
    Greg Comeau
    Oct 2, 2006
Loading...

Share This Page