471,066 Members | 1,283 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,066 software developers and data experts.

Help w/ "incomplete type" error

kj


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.
Nov 15 '05 #1
5 12098
kj <so***@987jk.com.invalid> 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
Nov 15 '05 #2
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.


Nov 15 '05 #3
Me
> 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).

Nov 15 '05 #4
On 6 Jul 2005 05:55:17 -0700, "Suman" <sk*****@gmail.com> 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
Nov 15 '05 #5


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.

Nov 15 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Lou Pecora | last post: by
1 post views Thread by sling blade | last post: by
2 posts views Thread by magyar.laszlo | last post: by
2 posts views Thread by unclefester | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.