This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Multiple declaration of the same variable

I builded a small project as follows:

=============================
int a;
int a; // Yes the same variable declared in the same way

main()
{ ...// anything
} =============================

this project is successfully compiled. No warnings.
Why ?
What is really performed:
1. Only one variable.
2. Two variable occupying different memory but for further using only one is accessible.

How to check such a possible duplicate declaration in very large project with many files included if there is no warnings for this case?

(If Variable name is the same but declarations are different [int and char for an example] error occurs as expected)

This was tested on uVision 2.30 Keil C51 7.02

Parents
  • I have, on some occasions, mistakeingly, 'doubled' a variable declaration and found that you only get one and no error which, whether it is as it should be or not, is a non-problem for me since my variable names are structured in such a way that there will be no two variables with the same name. I'm sure Mr. Smoked Sardine can answer whether it is correct by the C standard, If he will take time to provide information instead of spewing bile, I do not care it is correct by the C standard or not.

    Now, when using 'insignificant' names such as 'a' you will, of course, risk thinking you have two different variables used in two different places, but that trap you set yourself by using 'insignificant' names.

    Erik

Reply
  • I have, on some occasions, mistakeingly, 'doubled' a variable declaration and found that you only get one and no error which, whether it is as it should be or not, is a non-problem for me since my variable names are structured in such a way that there will be no two variables with the same name. I'm sure Mr. Smoked Sardine can answer whether it is correct by the C standard, If he will take time to provide information instead of spewing bile, I do not care it is correct by the C standard or not.

    Now, when using 'insignificant' names such as 'a' you will, of course, risk thinking you have two different variables used in two different places, but that trap you set yourself by using 'insignificant' names.

    Erik

Children