Jump to content
  • Advertisement
Sign in to follow this  
bschwagg

Same-named variables

This topic is 4843 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

Hi all- I'm in need of some advice. I have this project (sloppily) written in C code. I've found there are variables #define'ed in headers that have the same name as other global variables in other files. It's really a global variable mess... The compiler seems to compile away without giving any hint of something being wrong. As I clean the code up I keep running into this problem. (Or I could be wrong about the compiler giving any indication, but the code is so big it's tough to tell) I'm sure this could be dangerous at some point because the code is so long the problem might hide out for a while, then crash unexpectedly. Is there a tool in unix/irix that will find multiply defined variables? Is there a tool that would help analyze or clean up some of my mess? I'm using the 'cc' compiler in Irix 5.3 Thanks -Brad

Share this post


Link to post
Share on other sites
Advertisement
I'm not sure what the problem is exactly... if the variable was truly defined more than once, I doubt any compiler will ignore that. If they co-existed at global level then either the compiler or linker is going to run into problems when you build it.

Share this post


Link to post
Share on other sites
Up the warning level on the compiler.

But I'd have to agree with Kylotan. No compiler or linker would allow multiple definitions of the same variable. In the same scope

Cheers
Chris

Share this post


Link to post
Share on other sites
How can you #define variables? You #define constants - or, more precisely, macros.

Doing

#define Foo Bar
int Foo;


Is a perfectly valid C statement, and no compiler should ever issue a warning or an error about that.

Now, I may have misunderstood you. Cn you enlighten me by providing an example? (just the offending lines of code).

Regards,

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!