473,404 Members | 2,178 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Struct initialization leads to linker error

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
4 1322
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Gianni Mariani | last post by:
I posted a gcc bug http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13332 here is the text: ----------------------------------------------------------- This code will compile fine but fail on...
19
by: JustSomeGuy | last post by:
I have a class that has a static member variable. string x; x should never change during use and should be intialized to "abcd". How does one do this?
20
by: fix | last post by:
Hi all, I feel unclear about what my code is doing, although it works but I am not sure if there is any possible bug, please help me to verify it. This is a trie node (just similar to tree nodes)...
1
by: bvisscher | last post by:
I posted this recently in microsoft.public.vc.language and was redirected here. I also searched this ng and found some relavant threads. The most relavent I found was: ...
5
by: Jesper Schmidt | last post by:
When does CLR performs initialization of static variables in a class library? (1) when the class library is loaded (2) when a static variable is first referenced (3) when... It seems that...
4
by: hobbes992 | last post by:
Howdy folks, I've been working on a c project, compiling using gcc, and I've reached a problem. The assignment requires creation of a two-level directory file system. No files have to be added or...
6
by: Daniel Rudy | last post by:
Hello Group. Please consider the following code: /* this table is used in the wipedevice routine */ static const struct wipe_t { uchar wte; /* wipe table entry */ } wipetable = {...
8
by: Travis | last post by:
struct Point { int x; int y; }; Point Lines = { {0,1}, {1,2},
5
by: ssylee | last post by:
I'm not sure if I can initialize members of a struct the lazy way. For example, let's say I have a struct defined as below: typedef struct _ABC { BOOL A; BOOL B; BOOL C; } ABC;
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.