Jump to content
  • Advertisement
Sign in to follow this  
kingnosis

Fun with storage-class specifiers

This topic is 4846 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a small program in which it has been quite convenient to use a couple of global anonymous structs. Everything compiles fine, but now that I'm at the end, I can't get the linkage right.
display.obj : fatal error LNK1179: invalid or corrupt file: duplicate COMDAT '??0<unnamed-tag>@@QAE@XZ'
I've got the anonymous structs declared in a header file. The header file is then included in all the source files that want to use the structs. I tried to use extern in front of the declarations, but that only gave me the old "unresolved external symbol". I know what I'm doing isn't quite right, but I'm not sure what to do to make it right. I appreciate any help. Thanks.

Share this post


Link to post
Share on other sites
Advertisement
I never make an object of a struct in a header file, it only gets confusing. What i would do is leave the definition there and extern an object of it around all the CPP files that need it.

ace

Share this post


Link to post
Share on other sites
You need an extern declaration in the header file and a non-extern definition in a single source file.

With an anonymous struct, you're in a bit of trouble, since you can't reuse the type name of the struct in the source file...

Share this post


Link to post
Share on other sites
Naming the structs was a backup plan, since I never get to use anonymous structs. [wink] But if that's the only way...

Thanks again.

Share this post


Link to post
Share on other sites

I was working on a little 5 file project, and basically this is what I was trying out:

global.h

// the anon struct
struct {
bool flag;
int value;
} someData;



source1.cpp

#include "global.h"

// use that data here
void someFunc1() {
someData.flag = true;
}



source2.cpp

// and use that same data here
void someFunc2() {
if(someData.flag)
someData.value = 100;
else
someData.value = 200;
}


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!