By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,231 Members | 1,744 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,231 IT Pros & Developers. It's quick & easy.

Struct initialization leads to linker error

P: n/a
Hello all!

In my game, I have a structure defined as follows:

typedef struct vegetation {
vegetation_type type;
bool harvested;
int wood_yield;
int fruit_content;
int asciiChar;
int color;
char description[];
} vegetation;

Later in the same header, I instantiate this type as follows:

vegetation VEG_NONE = {VEG_TYPE_NONE,false,0,0,0,0,"None"};

This is obviously required, since the flexible array-member cannot be
dynamically initialized.

However, the linker cokes on this with the following error message:

main.c: multiple definition of `VEG_NONE'
graphics.c: first defined here

Why is this? I have properly encapsulated the header file in an
#ifndef,#define, #endif structure. So what could be happening?

--

Cheers,

John den Haan
joDhn[dot]haEan[at]chLello[dot]nl

Remove capital 'DEL' from above addy to obtain e-mail address
Feb 25 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Never mind, I sorted it out. Looks liek there was a hiatus in my
knowledge concerning multiple inclusion and the use of externs ;)

Thanks anyways
Feb 25 '07 #2

P: n/a
Well then, I got the linker error sorted out.

Now the compiler chokes on the following:

vegetation VEG_GRASS =
{VEG_TYPE_GRASS,false,0,0,ASCII_GRASS,COLOR_GRASS, "Grass"};

It tells me:

error: syntax error before ';' token

It seems to dislike the use of a #defined constant in the initialization
of the struct. What can I do to circumvent this problem? enums seem to
work (as shown by VEG_TYPE_GRASS, which is graciously accepted), but
#define's do not. I;ve tried explicit typecasting of the define, but it
doesn't do the job...
Feb 25 '07 #3

P: n/a
John den Haan wrote:
Well then, I got the linker error sorted out.

Now the compiler chokes on the following:

vegetation VEG_GRASS =
{VEG_TYPE_GRASS,false,0,0,ASCII_GRASS,COLOR_GRASS, "Grass"};

It tells me:

error: syntax error before ';' token

It seems to dislike the use of a #defined constant in the initialization
of the struct. What can I do to circumvent this problem? enums seem to
work (as shown by VEG_TYPE_GRASS, which is graciously accepted), but
#define's do not. I;ve tried explicit typecasting of the define, but it
doesn't do the job...
You have not provided enough information, but I'll guess
that you did something like

#define ASCII_GRASS 'G';
instead of
#define ASCII_GRASS 'G'

--
Eric Sosman
es*****@acm-dot-org.invalid
Feb 25 '07 #4

P: n/a
You have not provided enough information, but I'll guess
that you did something like

#define ASCII_GRASS 'G';
instead of
#define ASCII_GRASS 'G'
OMG. You're right :D

--

Cheers,

John den Haan
joDhn[dot]haEan[at]chLello[dot]nl

Remove capital 'DEL' from above addy to obtain e-mail address
Feb 25 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.