Same-named variables

Started by
2 comments, last by Emmanuel Deloget 18 years, 10 months ago
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
cha cha cha
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.
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
CheersChris
How can you #define variables? You #define constants - or, more precisely, macros.

Doing
#define Foo Barint 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,

This topic is closed to new replies.

Advertisement